UIbutton文字左 图片右

//创建UIButton并设置约束
UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:moreButton];
[moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo (_titlesLabel);
        make.right.mas_equalTo (self).offset(-EDGE_WIDTH);
        make.width.mas_equalTo (60 * KWIDTH_IPHONE6_SCALE);
        make.height.mas_equalTo (24 * KHEIGHT_IPHONE6_SCALE);
    }];
    //设置button属性
    moreButton.backgroundColor = [UIColor whiteColor];
    [moreButton setTitle:@"更多" forState:UIControlStateNormal];
    moreButton.titleLabel.font = [UIFont pingFang_RegularWithSize:14.0];
    [moreButton setTitleColor:[UIColor color102] forState:UIControlStateNormal];
    
    [moreButton setImage:[UIImage imageNamed:@"arrowGrayRight"] forState:UIControlStateNormal];
    //设置内部文字 图片位置 文字左 图片右
    [moreButton setTitleEdgeInsets:UIEdgeInsetsMake(0, -moreButton.imageView.bounds.size.width*1.2, 0, moreButton.imageView.bounds.size.width)];
    [moreButton setImageEdgeInsets:UIEdgeInsetsMake(0, moreButton.titleLabel.bounds.size.width*1.2, 0, -moreButton.titleLabel.bounds.size.width)];
    [moreButton addTarget:self action:@selector(moreButtonAction) forControlEvents:UIControlEventTouchUpInside];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • (一)Masonry介绍 Masonry是一个轻量级的布局框架 拥有自己的描述语法 采用更优雅的链式语法封装自动布...
    木易林1阅读 2,390评论 0 3
  • Masonry是一个轻量级的布局框架,拥有自己的描述语法,采用更优雅的链式语法封装自动布局,简洁明了并具有高可读性...
    3dcc6cf93bb5阅读 1,828评论 0 1
  • 一、前言 关于苹果的布局一直是我比较纠结的问题,是写代码来控制布局,还是使用storyboard来控制布局呢?以前...
    iplaycodex阅读 2,476评论 0 1
  • iOS_autoLayout_Masonry 概述 Masonry是一个轻量级的布局框架与更好的包装AutoLay...
    指尖的跳动阅读 1,195评论 1 4
  • 麻煩你要做到哦,對那些人…… 那些人,指除我之外的其他男人哦……
    帶風走路deFENG阅读 141评论 0 1