标签:
.h文件
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property(nonatomic,strong)NSTimer *timer;
--------------------------------------------------------——————————————————
.m文件
#import "ViewController.h"
@interface ViewController ()
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//实例化标签对象
UILabel *lable=[[UILabel alloc]initWithFrame:CGRectMake(20, 30, 200, 40)];
//设置字体的内容
lable.text=@"hello";
// lable.textColor=[UIColor whiteColor];//设置字体的颜色
lable.font=[UIFont fontWithName:@"Arial" size:60];//设置字体样式
//标签文字居中
lable.textAlignment=NSTextAlignmentCenter;
//标签背景颜色
lable.backgroundColor=[UIColor redColor];
// 设置标签边框的宽度
lable.layer.borderWidth=1;
// 设置边框的颜色
lable.layer.borderColor=[UIColor redColor].CGColor;
// 设置圆角边框
// lable.layer.cornerRadius=100;
//设置阴影
lable.layer.shadowColor=[UIColor blackColor].CGColor;
lable.layer.shadowOffset=CGSizeMake(10, 20);//阴影大小
lable.layer.shadowRadius=20;
//设置字体:粗体,正常的是SystemFontOfSize
lable.font = [UIFont boldSystemFontOfSize:20];
//设置lable 的行数
lable.numberOfLines = 2;
//设置lable中文字是否可变,默认为YES;
lable.enabled = NO;
//设置高亮
lable.highlighted = YES;
lable.highlightedTextColor = [UIColor orangeColor];
//将控件添加到当前图层上
[self.view addSubview:lable];
//-----------关于UITextFeild------
UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(10, 100, 200, 50)];
//设置输入框边框样式
textField.borderStyle=UITextBorderStyleLine;
//设置输入框的加密显示
textField.secureTextEntry=YES;
//设置输入框的字体居中位置
textField.textAlignment=NSTextAlignmentCenter;
//当输入框没有内容时,水印提示placeholder 提示内容为password
textField.placeholder=@"提示";
//设置属性
[self.view addSubview:textField];
//-----------关于UIButton------
// 设置定义按钮
UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(20, 200, 100, 80)];
// 设置按钮标题
[button setTitle:@"按钮" forState:UIControlStateNormal];
// 设置标题颜色
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//设置按钮背景图片
// [button setBackgroundImage:[UIImage imageNamed:@"0"] forState:UIControlStateNormal];
// 设置按钮背景颜色
button.backgroundColor=[UIColor redColor];
// 添加按钮事件
[button addTarget:self action:@selector(dianJi:) forControlEvents:UIControlEventTouchUpInside];
//设置按钮边框
[button.layer setCornerRadius:10.0]; //设置矩形四个圆角半径
[button.layer setBorderWidth:1.0]; //边框宽度
[button.layer setBorderColor:[UIColor blueColor].CGColor];//边框颜色
[self.view addSubview:button];
// 添加定时器
_timer=[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(fangFa) userInfo:nil repeats:YES];
}
-(void)fangFa{
NSLog(@"jjjjj");
}
-(void)dianJi:(UIButton *)sender{
NSLog(@"点了~");
[_timer invalidate];//定时器永久停止
_timer=nil;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
标签:
原文地址:http://my.oschina.net/u/2483781/blog/530845