美文网首页
按钮实现文字在下,图片在上

按钮实现文字在下,图片在上

作者: withdrawn_king | 来源:发表于2017-09-06 09:52 被阅读0次

    //按钮实现文字在下,图片在上

    -(void)initButton:(UIButton*)btn{
       btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
       // 按钮图片和标题总高度
       CGFloat totalHeight = (btn.imageView.frame.size.height + btn.titleLabel.frame.size.height);
       // 设置按钮图片偏移
       [btn setImageEdgeInsets:UIEdgeInsetsMake(-(totalHeight - btn.imageView.frame.size.height), 0.0, 0.0, -btn.titleLabel.frame.size.width)];
       // 设置按钮标题偏移
       [btn setTitleEdgeInsets:UIEdgeInsetsMake(0.0, -btn.imageView.frame.size.width, -(totalHeight - btn.titleLabel.frame.size.height),0.0)];
    }

    相关文章

      网友评论

          本文标题:按钮实现文字在下,图片在上

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