1.Label
UILabel *label = [[UILabel alloc]init];//创建
self.label = label;//关联到当前属性
label.text = @"显示的内容";//显示的内容
CGFloat width = self.view.bounds.size.width; //获取屏幕的宽度
label.frame = CGRectMake( width * 0.5 - 150, 40, 300, 200);//位置和大小label.backgroundColor = [UIColor lightGrayColor]; //背景颜色
label.font = [UIFont italicSystemFontOfSize:30]; //设置字体,斜体加字号
label.font = [UIFont systemFontOfSize:30];//设置字号
subLb.font = [UIFont boldSystemFontOfSize:30]; //设置字体,加粗
label.textColor = [UIColor redColor]; //设置文字的颜色
label.textAlignment = NSTextAlignmentCenter; //设置对齐方式(默认是左对齐)
label.numberOfLines = 0; //最多显示多少行文字,默认是1行,0代表任意行
[lb sizeToFit];//sizeToFit
会把 label 的当前宽度当做最大宽度,执行之后宽度只会比变窄,不会变宽
label.shadowColor = [UIColor blackColor];//设置label文字的有阴影
label.shadowOffset = CGSizeMake(1, 1); //设置label文字阴影倾斜45度
[UILabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:20]];//加
[UILabel setFont:[UIFont fontWithName:@"Helvetica-BoldOblique" size:20]];//加粗并且倾斜
[self.view addSubview:label];//将书签添加到相应视图中
// [attrString addAttributes:@{NSStrikethroughStyleAttributeName:@(NSUnderlineStyleSingle),NSBaselineOffsetAttributeName:@(0)} range:[priceString rangeOfString:@"¥88000"]];//加中间斜线
NSString *message = @“输入文字”;
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSFontAttributeName] = [UIFont systemFontOfSize:18];
CGSize textSize = [message boundingRectWithSize:CGSizeMake(SCREEN_WIDTH- 20,100) options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
2.Button
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
[button setTitle:@"按钮名" forState:UIControlStateNormal];
button.frame = CGRectMake(100, 260, 300, 40);
button.titleLabel.font = [UIFont systemFontOfSize:30];//设置字号
buttonF.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;//设置对齐方式
NSString *title = [button titleForState:UIControlStateNormal];
button.backgroundColor = [UIColor grayColor];
[self.view addSubview:button];
3.按钮响应
[button addTarget:self action:@selector(buttonTap) forControlEvents:
UIControlEventTouchUpInside];
- (void)buttonTap{//点击按钮后执行的方法
self.label.text = @"内容被改变了吧...";
}