美文网首页
图片和按钮垂直居中显示

图片和按钮垂直居中显示

作者: 毛豆爱吃奶 | 来源:发表于2019-12-02 18:05 被阅读0次

button上图片在上,文字在下并且居中显示:

-(void)setButtonContentCenter:(UIButton *) btn{

    CGSizeimgViewSize,titleSize,btnSize;

    UIEdgeInsetsimageViewEdge,titleEdge;

    CGFloatheightSpace =5.0f;

    //设置按钮内边距

    imgViewSize = btn.imageView.bounds.size;

    titleSize = btn.titleLabel.bounds.size;

    btnSize = btn.bounds.size;

    imageViewEdge =UIEdgeInsetsMake(heightSpace,0.0, btnSize.height-imgViewSize.height- heightSpace, - titleSize.width);

    [btnsetImageEdgeInsets:imageViewEdge];

    titleEdge =UIEdgeInsetsMake(imgViewSize.height+heightSpace+3, - imgViewSize.width,0.0,0.0);

    [btnsetTitleEdgeInsets:titleEdge];

}

相关文章

网友评论

      本文标题:图片和按钮垂直居中显示

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