美文网首页
UIbutton文字左 图片右

UIbutton文字左 图片右

作者: iOS_Developer | 来源:发表于2018-07-04 19:00 被阅读104次
    //创建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];
    

    相关文章

      网友评论

          本文标题:UIbutton文字左 图片右

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