已经以编程方式创建了一个UIButton
,一切都按预期工作,但我如何才能使用 IB 仅在视图上定位对象?
更准确地说,我喜欢仅将 IB 用于此行(请参阅:setViaIB)
self.searchBtn.frame = CGRectMake(setViaIB, setViaIB, 36, 36);
创建的完整代码UIButton
:
self.searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.searchBtn.frame = CGRectMake(100, 0, 36, 36);
[self.searchBtn setBackgroundImage:[UIImage imageNamed:@"search.png"] forState:UIControlStateNormal];
[self.searchBtn addTarget:self action:@selector(searchBtnTapped::) forControlEvents:UIControlEventTouchUpInside];
[self.searchBtn setNeedsDisplay];
[self.view addSubview:self.searchBtn];