【发布时间】:2014-08-04 23:21:39
【问题描述】:
所以我有一个用于我的通用 UITextField 的自定义 clearButton。我正在尝试移动 clearButton,因为我的 uitextfield 的背景在右侧有一些设计内容。我需要将清除按钮推到大约 150 像素以上。
我尝试了所有这些组合,但最终将清除按钮推离屏幕或使清除按钮非常宽,因此 uitextfield 中的文本停止变短。
第一次尝试
UIButton *clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect rect;
UIEdgeInsets contentInsets;
CGRect result;
[clearBtn setImage:[UIImage imageNamed:@"design.png"] forState:UIControlStateNormal];
rect = CGRectMake(0, 0, 45, 45);
contentInsets = UIEdgeInsetsMake(0, 50, 0, 0);
result = UIEdgeInsetsInsetRect(rect, contentInsets);
[clearBtn setFrame:result];
第二次尝试
UIButton *clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect rect;
UIEdgeInsets contentInsets;
CGRect result;
[clearBtn setImage:[UIImage imageNamed:@"design.png"] forState:UIControlStateNormal];
rect = CGRectMake(0, 0, 45, 45);
contentInsets = UIEdgeInsetsMake(0, 250, 0, 150);
result = UIEdgeInsetsInsetRect(rect, contentInsets);
[clearBtn setFrame:result];
【问题讨论】:
标签: ios objective-c uitextfield uiedgeinsets