【问题标题】:Set corner radius of `UISegmentedControl` equal to that of `UISearchController`设置 `UISegmentedControl` 的角半径等于 `UISearchController`
【发布时间】:2017-12-06 17:34:56
【问题描述】:
我在一个页面上有几个框,我希望它们都在该页面上具有UISearchController 的圆角半径。
我尝试将分段控件的圆角半径设置为等于搜索控制器的圆角半径。但是,_searchController.searchBar.layer.cornerRadius 在viewDidLoad 和viewDidAppear 中都返回0 而不是它的实际值。
我尝试了搜索栏内的文本字段,但它也返回 0 的角半径。
【问题讨论】:
标签:
ios
objective-c
user-interface
uisearchcontroller
【解决方案1】:
#define CornerRadius 6
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
[self.userNameTextfield.layer setCornerRadius:CornerRadius];
[self.userNameTextfield.layer setBorderColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_login"]].CGColor];
[self.userNameTextfield.layer setBorderWidth:1.0];
[self.userNameTextfield.layer setMasksToBounds:YES];
[self.passwordTextfield.layer setCornerRadius:CornerRadius];
[self.passwordTextfield.layer setBorderColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_login"]].CGColor];
[self.passwordTextfield.layer setBorderWidth:1.0];
[self.passwordTextfield.layer setMasksToBounds:YES];
// Do any additional setup after loading the view, typically from a nib.
}
像这样设置两个角的半径