您的位置:首页 > 产品设计 > UI/UE

IOS总结_实现UIButton的图文混排(二)

2014-11-13 18:09 288 查看
很久没有写博客了,之前写过一篇关于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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: