标签:style blog http io color ar os sp for
很久没有写博客了,之前写过一篇关于UIButton图文混排的,但是有点复杂,今天来一个比较简单地,相信大家回用得着
UIButton *button=[[UIButton alloc] initWithFrame:CGRectMake(60, 90, 100, 40)];
//加文字
[button setTitle:@"描述文字" forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//加图片
[button setImage:[UIImage imageNamed:@"pulldown"] forState:UIControlStateNormal];
//加边框
button.layer.borderColor=[UIColor redColor].CGColor;
button.layer.borderWidth=0.5;
这就是不改变位置的情况下混排的效果,根据大家不同的需要大家肯定会改变其位置
//改变图文位置 左右并排
button.titleEdgeInsets=UIEdgeInsetsMake(0, -button.imageView.frame.size.width, 0, button.imageView.frame.size.width);
button.imageEdgeInsets=UIEdgeInsetsMake(0, button.titleLabel.frame.size.width+5, 0, 0);
说明:EdgeInsets的位置是相对改变的,具体大家可以更具代码去理解
[self.view addSubview:button];
标签:style blog http io color ar os sp for
原文地址:http://blog.csdn.net/yxiaoping/article/details/41083789