Label、Button

 

 

 

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 = @"内容被改变了吧...";   

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值