简体   繁体   English

将“ UISegmentedControl”的角半径设置为等于“ UISearchController”的角半径

[英]Set corner radius of `UISegmentedControl` equal to that of `UISearchController`

I have several boxes on a page and I would like them all the have the corner radius of the UISearchController also on that page. 我在页面上有几个框,我希望它们在该页面上都具有UISearchController的角半径。

I tried to set the corner radius of my segmented control equal to that of the search controller. 我试图将分段控件的角半径设置为等于搜索控制器的角半径。 However, _searchController.searchBar.layer.cornerRadius returns 0 instead of its actual value in both viewDidLoad and viewDidAppear . 但是, _searchController.searchBar.layer.cornerRadius返回0而不是viewDidLoadviewDidAppear中的实际值。

I tried the textfield inside of the search bar, but it also returns 0 for its corner radius. 我尝试了搜索栏内的文本字段,但它的拐角半径也返回0

#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.
}

set both corner radius like this 像这样设置两个拐角半径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM