IOS UIButton 左边文字右边图片

       UIButton *openVipBtn = [UIButton buttonWithType:UIButtonTypeCustom];

        openVipBtn.frame = CGRectMake(0,100, 60, 17);

        [openVipBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

        openVipBtn.titleLabel.font = [UIFont systemFontOfSize:16];

        [openVipBtn setImage:[UIImage imageNamed:@"handwriting"] forState:UIControlStateNormal];

        [cell.contentView addSubview:openVipBtn];

        

        NSString *title = @"你好";

        [openVipBtn setTitle:title forState:UIControlStateNormal];

        CGFloat leftlab = [title sizeWithAttributes:@{NSFontAttributeName : openVipBtn.titleLabel.font}].width;

        [openVipBtn setImageEdgeInsets:UIEdgeInsetsMake(0, leftlab + 50, 0, 0)];

        [openVipBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -40, 0, 0)];

你可能感兴趣的:(iOS开发)