UIButton(改变Title和image位置)

 

 UIButton *btn = [[UIButton alloc] init];
    [btn setFrame:frame];
    [btn setTitleColor:titleColor forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [btn setImage:normalI forState:UIControlStateNormal];
  //按钮内容对齐方式
     btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
   //按钮image位置
 btn.imageEdgeInsets = UIEdgeInsetsMake(0,btn.titleLabel.bounds.size.width, 0,-btn.titleLabel.bounds.size.width);
    //按钮title的位置
    btn.titleEdgeInsets = UIEdgeInsetsMake(0,-btn.imageView.image.size.width, 0, btn.imageView.image.size.width);
  //按钮图片自适应
     btn.imageView.contentMode= UIViewContentModeScaleAspectFit;

        

 

posted @ 2015-11-25 20:57  TheYouth  阅读(485)  评论(0编辑  收藏  举报