您好,欢迎来到知库网。
搜索
您的当前位置:首页iOS如何在UIButton上设置图片文字上下对其

iOS如何在UIButton上设置图片文字上下对其

来源:知库网

UIButton *EndBut = [UIButton buttonWithType:UIButtonTypeCustom];

    EndBut.frame = CGRectMake(Screen_W-47*YZAdapter, 0, 35*YZAdapter, 43);

    [EndBut setImage:[UIImage imageNamed:@"已完成订单"] forState:UIControlStateNormal];

    [EndBut setTitle:@"已完成" forState:UIControlStateNormal];

    EndBut.titleLabel.font = FONT(10);

    [EndBut setTitleColor:MainFont_Color forState:UIControlStateNormal];

    EndBut.backgroundColor = YZBackNavColor;

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

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

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

Copyright © 2019- zicool.com 版权所有 湘ICP备2023022495号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务