.h文件ide
#import <UIKit/UIKit.h>字體
@interface ViewController : UIViewControlleratom
@property(nonatomic,strong)NSTimer *timer;加密
@end spa
--------------------------------------------------------——————————————————.net
.m文件3d
#import "ViewController.h"orm
@interface ViewController ()對象
@end 事件
@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