Searchbar in IOS (search box) cursor initial position after moving _ios

Source: Internet
Author: User
Tags border color uikit

Nonsense not to say more, directly to everyone to paste the key code, the specific code as follows:

#import <UIKit/UIKit.h> @interface Searchbar:uitextfield @property (nonatomic,strong) UIButton *button;
+ (instancetype) Searchbar; @end #import "SearchBar.h" @implementation Searchbar-(ID) initWithFrame: (CGRect) frame {self = [super Initwithframe:fram
E]; if (self) {self.font = [Uifont systemfontofsize:15]; self.placeholder = @ "Enter breed keyword";//set Border and border color SELF.BORDERSTYLE=UITEXTB
Orderstylenone;
self.layer.cornerradius=15.0f;
Self.layer.maskstobounds=yes;
Self.layer.bordercolor=[[uicolor colorwithred:224/255.0 green:243/255.0 blue:223/255.0 Alpha:1.0]CGColor];
Self.layer.borderwidth= 2.0f;
UIButton *button = [[UIButton alloc] Initwithframe:cgrectmake (0, 0, 40, 30)];
[Button setbackgroundimage:[uiimage imagenamed:@ "Seachbar_rightview"] forstate:uicontrolstatenormal];
[Button settitle:@ "search" forstate:uicontrolstatenormal]; [Button Settitlecolor:[uicolor colorwithred:119/255.0 green:166/255.0 blue:16/255.0 alpha:1.0] ForState:
UIControlStateNormal]; Button.titleLabel.font = [Uifont Systemfontofsize:18.0];
Button.titleLabel.textColor = [Uicolor colorwithred:119/255.0 green:166/255.0 blue:16/255.0 alpha:1.0];
Button.titleLabel.textColor = [Uicolor Redcolor];
Self.rightview = button;
Self.rightviewmode = Uitextfieldviewmodealways;
This sets the cursor position so that the cursor position is moved after ten self.leftview = [[UIView alloc]initwithframe:cgrectmake (0, 0, 10, 0)];
Self.leftviewmode = Uitextfieldviewmodealways;
return self; } + (Instancetype) Searchbar {return [[Self alloc] init];}

Below is a description of the cursor position of the setting input box in iOS

This sets the cursor position so that the cursor position is moved after ten
textfield.leftview = [[UIView alloc]initwithframe:cgrectmake (0, 0, 0)];
Textfield.leftviewmode = Uitextfieldviewmodealways;

The above is a small set to introduce the iOS searchbar (search box) cursor initial position after the move, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

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.