How can i make a more rounded UITextField? Like the search field in Safari on iPad

后端 未结 5 717
夕颜
夕颜 2021-02-08 21:53

HI I\'m trying to get a UITextField to look like the google search field available in the safari app on iPad. The purpose of the field will be the same (a search box).

I

5条回答
  •  再見小時候
    2021-02-08 22:19

    Use the below code.It works for me:

    searchField= [[UITextField alloc] initWithFrame:CGRectMake(0,0,150,31)];
    searchField.delegate = self;
    searchField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    searchField.textColor = [UIColor colorWithRed:102.0/255 green:102.0/255 blue:102.0/255 alpha:1.0];
    searchField.textAlignment = UITextAlignmentLeft;
    searchField.font = [UIFont fontWithName:@"Helvetica" size:15];
    searchField.autocorrectionType = UITextAutocorrectionTypeNo;
    searchField.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter;
    searchField.clearsOnBeginEditing = NO;
    searchField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    searchField.autocorrectionType = UITextAutocorrectionTypeNo;
    searchField.keyboardType = UIKeyboardTypeURL;
    searchField.returnKeyType = UIReturnKeySearch;        
    searchField.clearButtonMode = UITextFieldViewModeWhileEditing;
    searchField.rightViewMode = UITextFieldViewModeUnlessEditing;
    searchField.layer.cornerRadius = 17;
    searchField.placeholder=@"Google Search";
    searchField.borderStyle = UITextBorderStyleRoundedRect;//To change borders to rounded
    searchField.layer.borderWidth = 1.0f; //To hide the square corners 
    searchField.layer.borderColor = [[UIColor grayColor] CGColor]; //assigning the default border color
    UIBarButtonItem *searchFieldItem = [[UIBarButtonItem alloc] initWithCustomView:searchField];
    

提交回复
热议问题