1. Set the UIButton button content
//Set the custom button//UIButton *button1=[uibutton Buttonwithtype:uibuttontypecustom];//set a rounded buttonUIButton *button1=[UIButton buttonwithtype:uibuttontyperoundedrect];button1.frame=cgrectmake ( the, -, -, -);//position coordinates of the button[Button1 Settitle:@"Button1"Forstate:uicontrolstatenormal];//Normal Status button title[Button1 Settitle:@"Highlight State"Forstate:uicontrolstatehighlighted];//button title in highlighted State//Highlight Status Glow effect[button1 Setshowstouchwhenhighlighted:yes];//set the color of a caption[button1 Settitlecolor:[uicolor Redcolor] forstate:uicontrolstatenormal];//set the font size for headings[Button1.titlelabel Setfont:[uifont Boldsystemfontofsize: -]];//Set Background color[button1 Setbackgroundcolor:[uicolor Bluecolor];//picture is stretched to set background picture[Button1 Setbackgroundimage:[uiimage imagenamed:@"1.jpg"] forstate:uicontrolstatenormal];//picture keeps the original size set background picture//[button1 setimage:[uiimage imagenamed:@ "1.jpg"] forstate:uicontrolstatenormal];[[button1 Titlelabel]setshadowcolor:[uicolor Blackcolor]]; [[Button1 Titlelabel]setshadowoffset:cgsizemake (-0.5, -0.5)];button1.contenthorizontalalignment=Uicontrolcontenthorizontalalignmentleft; [Self.view Addsubview:button1];//Monitoring Events[Button1 addtarget:self Action: @selector (Click_button) forcontrolevents:uicontroleventtouchupinside];}-(void) Click_button{nslog (@"clicked ...");}
2. Set the picture contents of Uiimageview
1. Instantiate the control uiimageview *img = [[Uiimageview alloc] init]; Shorthand Uiimageview *img = [Uiimageview new]; 2. Set the contents of the control, the following background is the picture name, just drag into the project's assets file can img.image = [UIImage imagenamed:@ "background"]; 3. Set the control's frame (coordinate) img.frame = CGRectMake (0, 0,.); 4. Add the parent control [Self.view addsubview:img];
2.3Use the Transform property Imageview.transform=cgaffinetransformmaketranslation (cgfloat dx, cgfloat dy), where dx and dy indicate how much you want to move in the X or Y direction, rather than how much. 3, rotating image imageview.transform=cgaffinetransformmakerotation (cgfloat angle); Note that it rotates in a clockwise direction, and the center of the rotation is the center of the original ImageView, which is the position represented by the Center property. The parameter of this method is angle in radians, not our most commonly used degree, so you can write a macro definition:#defineDegreestoradians (x) (m_pi* (x)/180.0)4, scale an image, or use the Transform property: Imageview.transform=Cgaffinetransformmakescale (cgfloat scale_w, CGFloat scale_h);
5, add a click event for a picture: imageview.userinteractionenabled=yes;//enables the control to interact UITapGestureRecognizer*singletap =[[UITapGestureRecognizer alloc] initwithtarget:self action: @selector (Tapimageview:)];[ ImageView Addgesturerecognizer:singletap]; Be sure to first set the userinteractionenabled to Yes so that you can respond to the Click event6. Other Settings Imageview.hidden= yes or no;//hide or show picturesImageview.alpha = (cgfloat) al;//Set TransparencyImageview.highlightedimage = (UIImage *) hightlightedimage;//set the picture to display when highlightingImageview.image = (UIImage *) image;//set up a picture for normal display[ImageView SizeToFit];//resize the picture to be the same as the content picture
3. Setting the Uilabel property content
Set label (tag) Label.tag=101; Set the text content of a label Label.text=@"ABCD"sets the text type and size of the label Label.font= [Uifont systemfontofsize: A];//Use system default text to set the sizeLabel.font = [Uifont fontwithname:@"Arial"Size -];//set Text type and sizesets the text color of a label Label.textcolor= [Uicolor Lightgraycolor];//where TextColor to use the Uicolor typesets the alignment of text label.textalignment=Nstextalignmentleft, where there are three ways to set TextAlignment: Nstextalignmentleft to the left, Nstextalignmentcenter to center, Nstextalignmentright is aligned to the right if there are some articles introduced with Uitextalignmentcenter/uitextalignmentleft/Uitextalignmentright, that is iOS6 previous usage, IOS6 's latest usage has been changed when the text content is many, label can not display all when the label will be the text content in the way of ellipses instead, Here's how to set the label text ellipsis Label.linebreakmode=nslinebreakbycharwrapping;//where the Linebreakmode optional value isLinbreakmodeenum{nslinebreakbywordwrapping=0,//keep the whole word, with a space as the boundaryNslinebreakbycharwrapping,//Preserve entire charactersNslinebreakbyclipping,//so far as the borderNslinebreakbytruncatinghead,//omit the beginning and replace it with an ellipsisNslinebreakbytruncatingtail,//omit end, replace with ellipsisNslinebreakbytruncatingmiddle//omit middle, replace with ellipsis} Sets the number of lines of text Label.numberoflines=0;//The number of rows is set to 1, when not set, the system defaults to 1, which is set to 0 o'clock, which means wrapping, but requires a given control width .set the size of the control's adaptive Content [Label SizeToFit]; Set the label's border weight and color, and add it to the corresponding file before setting it#import<QuartzCore/QuartzCore.h>Label.layer.borderColor= [Uicolor Lightgraycolor]. Cgcolor;//border color, to be CgcolorLabel.layer.borderWidth =1;//Border Widthsets the label's background color Label.backgroundcolor=[Uicolor Yellowcolor]; setting a background map allows you to place a picture of the same size as a label on the back layer of the label, and then set the label's background to Transparent so that the label has a background Uilabel* label = [[UILabel alloc] Initwithframe:cgrectmake ( -, -, $, -)]; Uiimageview*imageview =[[Uiimageview alloc]init]; Imageview.frame=cgrectmake ( -, -, $, -); UIImage*image=[uiimage imagenamed:@"1.jpg"]; Imageview.image=image;//ImageView will change the size of the added picture according to its size, so no additional settings are required for the imageLabel.backgroundcolor =[Uicolor Clearcolor]; Label.text=@"Hello World"; Label.font= [Uifont systemfontofsize: -]; Label.textcolor=[Uicolor Yellowcolor]; [Self.view Addsubview:imageview];//The order cannot be added incorrectly, otherwise the picture will overwrite the label[Self.view Addsubview:label]; Set Text Shadow Label.shadowcolor=[Uicolor Graycolor]; set Shadow size Label.shadowoffset= Cgsizemake (2.0,2.0); Set the label fillet Label.layer.cornerRadius=TenIf you want to use such a setting, you must first add the file in the header#import<QuartzCore/QuartzCore.h>
4. Setting the TextField property content
Define a Textfieldusernamefield= [[Uitextfield alloc] Initwithframe:cgrectmake (usernameimg.frame.origin.x+ -, USERNAMEIMG.FRAME.ORIGIN.Y,165, +)]; Usernamefield.placeholder=@"User Name"; Usernamefield.attributedplaceholder= [[Nsattributedstring alloc] initwithstring:@"Mobile phone number"attributes:@{Nsforegroundcolorattributename:placeholdercolor}]; The above sentence is set Placeholde The color of R, Placeholdercolor is the color you need Usernamefield.backgroundcolor=[Uicolor Clearcolor]; Usernamefield.Delegate=Self ; Usernamefield.contenthorizontalalignment=Uicontrolcontenthorizontalalignmentcenter; Usernamefield.contentverticalalignment=Uicontrolcontentverticalalignmentcenter; Usernamefield.borderstyle=Uitextborderstylenone; Usernamefield.font= [Uifont systemfontofsize:14.0]; [Self.view Addsubview:usernamefield];//set border style to show border style only if setText.borderstyle =Uitextborderstyleroundedrect; typedefenum{uitextborderstylenone, uitextborderstyleline, Uitextborderstylebezel, Uitextborderstyleroundedrect } Uitextborderstyle; //sets the background color of the input box, which is set to white if you use a custom background picture border is ignoredText.backgroundcolor =[Uicolor Whitecolor];//Set BackgroundText.background = [UIImage imagenamed:@"Dd.png"];//Set BackgroundText.disabledbackground = [UIImage imagenamed:@"Cc.png"];//When the input box does not have content, the watermark prompt content is passwordText.placeholder =@"Password";//set font style and size for input box contentsText.font = [Uifont fontwithname:@"Arial"Size20.0f];//Set Font ColorText.textcolor =[Uicolor Redcolor];//whether there is a fork in the input box, when it appears, to delete the contents of the input box at onceText.clearbuttonmode =Uitextfieldviewmodealways;typedefenum{uitextfieldviewmodenever, uitextfieldviewmodewhileediting is not present, uitextfieldviewmodeunlessediting appears when editing, In addition to editing appear uitextfieldviewmodealways always appear} Uitextfieldviewmode;//Enter the text from the beginning of the boxText.text =@"text at the beginning of the input box"; //every character you enter becomes a point. Password inputText.securetextentry =YES;//whether to correctText.autocorrectiontype =Uitextautocorrectiontypeno;typedefenum{uitextautocorrectiontypedefault, default Uitextautocorrectiontypeno, no automatic error correction Uitextautocorrectiontypeyes, automatic error correction } Uitextautocorrectiontype;//edit it again and empty it .Text.clearsonbeginediting =YES;//Content AlignmentText.textalignment =Uitextalignmentleft;//The vertical alignment of content Uitextfield inherits from Uicontrol, which has an attribute in this class contentverticalalignmentText.contentverticalalignment =Uicontrolcontentverticalalignmentcenter;//when set to Yes, the text automatically shrinks to fit the text window size. The default is to keep the original size and let long text scrollTextfied.adjustsfontsizetofitwidth =YES;//set the minimum font size for auto-shrink displayText.minimumfontsize = -;//Set the keyboard styleText.keyboardtype =Uikeyboardtypenumberpad;typedefenum{uikeyboardtypedefault, default keyboard, support for all character uikeyboardtypeasciicapable, ASCII-enabled default keyboard Uikeyboardtype Numbersandpunctuation, standard telephone keypad, support +*# character uikeyboardtypeurl, url keypad, support. com buttons only support URL character Uikeyboardtypenumberpad, Numeric keypad uikeyboardtypephonepad, telephone keypad uikeyboardtypenamephonepad, telephone keypad, also support input person name uikeyboardtypeemailaddress, Keyboard Uikeyboardtypedecimalpad for entering e-mail addresses, numeric keypad with digital and decimal uikeyboardtypetwitter, optimized keypad for easy input @, #字符 Uikeybo Ardtypealphabet=Uikeyboardtypeasciicapable,} Uikeyboardtype; //whether the first letter is capitalizedText.autocapitalizationtype =Uitextautocapitalizationtypenone;typedefenum{uitextautocapitalizationtypenone, do not automatically capitalize Uitextautocapitalizationtypewords, capitalize the first letter of the word Uitextautocapitalizati Ontypesentences, the first letter of the sentence is capitalized uitextautocapitalizationtypeallcharacters, all the letters are capitalized} Uitextautocapitalizationtype;
iOS notes (ii) control properties