- CGRect btnRect = CGRectMake(
- 360 * 0.5f,
- 352 * 0.5f,
- 107,
- 49
- );
- m_iknowBtn = [[UIButton alloc] initWithFrame:btnRect];
- [m_iknowBtn setTitle:FoolLocalizedString(@"知道了", nil) forState:UIControlStateNormal];
- [m_iknowBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- m_iknowBtn.titleLabel.font = [UIFont systemFontOfSize:18];
- m_iknowBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
- m_iknowBtn.titleLabel.minimumFontSize = 5;
- [m_iknowBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 18, 0)];
- [m_iknowBtn setBackgroundImage:[UIImage imageNamed:@"ipad_goodluck_iknow_btn.png"] forState:UIControlStateNormal];
- [m_iknowBtn addTarget:self action:@selector(closeLayer) forControlEvents:UIControlEventTouchUpInside];
关键在:
[m_iknowBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 10, 18, 0)];
其中
UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom,CGFloat right) {
UIEdgeInsets insets = {top, left, bottom, right};
return insets;
}
表示
这个表示title往右边偏移10像素,往上面偏移18像素。
第一个参数top如果为正表示往下偏移,第二个参数left如果为正表示往右偏远,第三个参数bottom如果为正表示往上偏移,第四个参数right如果为正表示往左偏移。
//右对齐
[login_btsetContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];