美文网首页
UIButton图片和文字

UIButton图片和文字

作者: iOS乐乐 | 来源:发表于2019-10-30 16:34 被阅读0次

图片在上文字在下

UIButton*btn=[[UIButton alloc]initWithFrame:CGRectMake(25, 0, 85, 130)];
    [btn setImage:[UIImage imageNamed:@"homeQian"] forState:(UIControlStateNormal)];
    [btn setTitle:@"我的积分 :" forState:(UIControlStateNormal)];
    btn.titleLabel.font=[UIFont systemFontOfSize:K_36Size];
    btn.titleLabel.adjustsFontSizeToFitWidth=YES;
    [btn setTitleColor:BlackColor forState:(UIControlStateNormal)];
    btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentCenter;
   btn.titleEdgeInsets = UIEdgeInsetsMake(30, -btn.imageView.frame.size.width, -btn.imageView.frame.size.height, 0);
            btn.imageEdgeInsets = UIEdgeInsetsMake(-btn.titleLabel.frame.size.height, 0, 0, -btn.titleLabel.frame.size.width);
    [_btmView addSubview:btn];

文字在左图片在右

[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, - btn.imageView.image.size.width, 0, btn.imageView.image.size.width)];
    [btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.bounds.size.width, 0, -btn.titleLabel.bounds.size.width)];

相关文章

网友评论

      本文标题:UIButton图片和文字

      本文链接:https://www.haomeiwen.com/subject/hitavctx.html