iOS中按钮边框及文字对齐设置

来源:互联网 发布:广东裤哥战哭淘宝女郎 编辑:程序博客网 时间:2024/06/18 01:33

- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    //创建UIButton

    UIButton *button1 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    button1.frame = CGRectMake(10, 30, 300, 30);

  

    [button1 setTitle:@"圆角按钮"forState:UIControlStateNormal];

//    这句无效

//     button1.titleLabel.textAlignment = NSTextAlignmentLeft;

    button1.titleLabel.backgroundColor = [UIColorgrayColor];


    button1.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;

    button1.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);

    [button1.layersetBorderColor:[UIColorgrayColor].CGColor];

    [button1.layer setBorderWidth:1];

    [button1.layer setCornerRadius:5.0f];

    [button1.layer setMasksToBounds:YES];

    [self.viewaddSubview:button1];

}

1 0
原创粉丝点击