UIButton 设置imageEdgeInsets titleEdgeInsets 图片和文字垂直

{
        //设置contentHorizontalAlignment contentVerticalAlignment 后 btn  的imageView orgin(0,0) titleLable origin(imgaview.image.size.width,0),
        _btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _btn.contentVerticalAlignment =UIControlContentVerticalAlignmentTop;
        CGSize bgsize = bg_normal.size;
        CGSize iconSize = icon_normal.size;
        //label 的字体为14号字
        CGFloat titleh = 16.0f,
        titlew = [_title sizeWithFont:titleFont].width,
        //图片和文字的间隔为8
        btnmargintitle = 8.0f,
        contenth = iconSize.height+titleh+ btnmargintitle,
        imginsettop = (bgsize.height-contenth)/2,
        imginsetLeft = (bgsize.width-iconSize.width)/2,
        titleinsetTop = imginsettop+btnmargintitle+iconSize.height,
        
        //titleEdgeInsets
        titleinsetLeftnew = (bgsize.width-titlew)/2,
        titleinsetLeftold = iconSize.width,
        titleinsetLeft = titleinsetLeftnew-titleinsetLeftold;
        
        
        _btn.imageEdgeInsets = UIEdgeInsetsMake(imginsettop, imginsetLeft, 0, 0);
        _btn.titleEdgeInsets = UIEdgeInsetsMake(titleinsetTop, titleinsetLeft, 0, 0);
    }


你可能感兴趣的:(UIButton,imageEdgeInsets,titleEdgeInsets,图片和文字垂直居中对齐)