美文网首页
iOS如何在UIButton上设置图片文字上下对其

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

作者: 小木惊风 | 来源:发表于2018-01-10 14:48 被阅读13次

    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];

    相关文章

      网友评论

          本文标题:iOS如何在UIButton上设置图片文字上下对其

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