博客> ios button图片文字上下排列
ios button图片文字上下排列
2017-11-23 05:00 评论:0 阅读:193 飞翔信念
ios button图片文字上下排列

其实还是改变button的imageedge和titleedge,

[button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
            [button setContentVerticalAlignment:UIControlContentVerticalAlignmentTop];

            CGFloat buttonWidth =DeviceWidth/4;//按钮的宽度
            CGFloat textWidth = [[CYTool sharedInstance] planRectWidth:titleArray[i] font:12];//按钮上的文字宽度
            CGFloat imageTopGap = 20;//图片距上部距离
            CGFloat textTopGap = 6;//文字距离图片的距离
            [button setImageEdgeInsets:UIEdgeInsetsMake(imageTopGap,(buttonWidth-button.imageView.frame.size.width)/2,0, 0)];
            [button setTitleEdgeInsets:UIEdgeInsetsMake((button.imageView.frame.size.height + imageTopGap) + textTopGap,(buttonWidth - textWidth)/2 - button.imageView.frame.size.width,0,0 )];
收藏
0
sina weixin mail 回到顶部