Button title的位置

button title 的位置是默认居中的。也可以根据需要设定它的位置。

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(50, 50, 200, 50);
    [self.view addSubview:button];
    [button setTitle:@"这是一个按钮" forState:UIControlStateNormal];
    
    button.backgroundColor = [UIColor redColor];
//  title居左  这种情况下,是完全靠近左边界的
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
   
contentHorizontalAlignment 是一个枚举类型,有:

然后按钮还有另外一个属性:

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

这个可以设置title相对边界的点。如果只是作用在上下边界,不需要添加

button.contentHorizontalAlignment

但是如果要作用到左右两边的边界,就要先设置一下
 button.contentHorizontalAlignment了。

 

 

 

 

 

 

 

 

posted @ 2015-07-03 14:35  FirMiana  阅读(228)  评论(0)    收藏  举报