IOS modifies the cursor cursor color and font style and size of the Searchbar textfiled; Disable input box

Source: Internet
Author: User

Because the cursor color and tint color of the search bar are uniform, if you want to set the cursor color to a different color, you need to modify it inside the textfiled, and the same for the font.

Implementation code:

-(void) setsearchbartextfiled: (Uisearchbar *) searchbar{for    (UIView *view in searchbar.subviews) {for        (ID Subview in view.subviews) {            if ([Subview Iskindofclass:[uitextfield class]) {                [(Uitextfield *) Subview Settintcolor:[uicolor Graycolor]];                [(Uitextfield *) Subview Setfont:[uifont Fontwithname:general_font size:13]];                return;}}}    

If you want to implement the user cannot enter into the search box, you need to textfiled the input invalidation:

One approach is to set the disable for the entire searchbar, but if there are other components, such as the scope button, it will also fail:

[Searchbar Setuserinteractionenabled:no];

Implementation code:

-(void) Enabletextinput: (Uisearchbar *) searchbar{for    (UIView *view in searchbar.subviews) {for        (ID subview in View.subviews) {            if ([Subview Iskindofclass:[uitextfield class]]) {                [Subview setenabled:yes];                return;}}}    -(void) Disabletextinput: (Uisearchbar *) searchbar{for    (UIView *view in searchbar.subviews) {for        (ID subview in View.subviews) {            if ([Subview Iskindofclass:[uitextfield class]]) {                [Subview setenabled:no];                return;}}}    
Reference Links:

Http://stackoverflow.com/questions/9968595/how-to-enable-cancel-button-with-uisearchbar

Http://stackoverflow.com/questions/11606007/change-uitextfield-and-uitextview-cursor-caret-color

Http://stackoverflow.com/questions/2190352/change-color-of-cursor-in-text-field

Http://stackoverflow.com/questions/9169049/disable-uisearchbar

IOS modifies the cursor cursor color and font style and size of the Searchbar textfiled; Disable input box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.