An example of how to adjust the text position in UIButton is as follows:
CGRect btnRect = CGRectMake (360 * 0.5f, 352 * 0.5f, 107, 49); m_iknowBtn = [[UIButton alloc] initWithFrame: btnRect]; [m_iknowBtn setTitle: break (@ "", nil) forState: UIControlStateNormal]; [m_iknowBtn setTitleColor: [UIColor whiteColor] forState: UIControlStateNormal]; break = [UIFont systemFontOfSize: 18]; response = YES; response = 5; [m_iknowBtn setTitleEdgeInsets: UIEdgeInsetsMake (0, 10, 18, 0)]; [m_iknowBtn setBackgroundImage: [UIImage imageNamed: @ "response"] forState: UIControlStateNormal]; [m_iknowBtn addTarget: self action: @ selector (closeLayer) forControlEvents: UIControlEventTouchUpInside];
The key lies in:
[M_iknowBtn
SetTitleEdgeInsets: UIEdgeInsetsMake (0, 10,
18, 0)];
Where
UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake (CGFloat top,
CGFloat left, CGFloat bottom,
CGFloat right ){
UIEdgeInsets insets = {top, left, bottom, right };
Return insets;
}
Indicates
This indicates that the title is shifted to the right by 10 pixels and 18 pixels to the top.
If the top of the first parameter is positive, it indicates a down offset. If the left of the second parameter is positive, it indicates a remote to the right. If the bottom parameter is positive, it indicates an up offset. If the right parameter is positive, it indicates a left offset.