iOS button 文字图片上下、左右排布

iOS button 文字图片上下/左右排布

上下:

    self.rechargeButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示

    [self.rechargeButton setTitleEdgeInsets:UIEdgeInsetsMake(self.rechargeButton.imageView.frame.size.height+10 ,-self.rechargeButton.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度,距离左边框减少imageView的宽度,距离下边框和右边框距离不变

    [self.rechargeButton setImageEdgeInsets:UIEdgeInsetsMake(-10, 0.0,0.0, -self.rechargeButton.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度,其它不边

 左右:

因为默认button  图片在左,文字在右, 下面代码是反过来的:   文字  图片

    [self.DetailButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -self.DetailButton.imageView.bounds.size.width, 0, self.DetailButton.imageView.bounds.size.width)];

    [self.DetailButton setImageEdgeInsets:UIEdgeInsetsMake(0, self.DetailButton.titleLabel.bounds.size.width, 0, -self.DetailButton.titleLabel.bounds.size.width)];

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 成都的秋和夏总是缠缠绵绵,直到十一月,也不尽然是完全的秋,偶尔还要来个二十多度,给人一种快要夏天的错觉。街道上,...
    yi梓君阅读 1,599评论 0 0
  • 你有没有一个关于爱或被爱的小故事,可以是朋友、亲人、爱人、陌生人,曾经在你人生的某个阶段,让你感到过被拯救呢? 有...
    Mjinxiu无忧阅读 1,391评论 9 12
  • 我最孤独是什么时候呢,大概就是我一个人去吃饭,不能中途去洗手,不能在想要走出这家店之前离开餐桌,否则那将意味着,不...
    佛系肉团阅读 2,833评论 3 1