I. UILabel
(1) initialize UILabel
<Span style = "color: #000000;"> UILabel * scoreLabel = [[UILabel alloc] initWithFrame: CGRectMake (self. bounds. size. width/2), 0.0, 150.0, 43.0)];
ScoreLabel. textAlignment = UITextAlignmentCenter;
ScoreLabel. text = @ "I'm Andy -- Qingfeng ";
ScoreLabel. textColor = [UIColor whiteColor];
ScoreLabel. backgroundColor = [UIColor blackColor];
ScoreLabel. font = [UIFont fontWithName: @ "Arial Rounded MT Bold" size: (36.0)];
[Self addSubview: scoreLabel]; </span>
(2) detailed parameter explanation
// Set the display text
ScoreLabel. text = @ "I'm Andy -- Qingfeng ";
// Set the font: bold. The system fontofsize is normal and the system font configuration is called.
ScoreLabel. font = [UIFont boldSystemFontOfSize: 20];
// Set the text color. You can select multiple colors.
ScoreLabel. textColor = [UIColor orangeColor];
ScoreLabel. textColor = [UIColor purpleColor];
// Set the text alignment position, Center, Center, and right
ScoreLabel. textAlignment = UITextAlignmentRight;
ScoreLabel. textAlignment = UITextAlignmentCenter;
// Set the font size to fit the label width
ScoreLabel. adjustsFontSizeToFitWidth = YES;
// Set the number of lines of the label, which can be self-adaptive Based on the UITextView in the previous section
ScoreLabel. numberOfLines = 2;
// Set whether the text is highlighted or not.
ScoreLabel. highlighted = YES;
ScoreLabel. highlightedTextColor = [UIColor orangeColor];
// Set the color of the shadow and the offset position of the shadow.
ScoreLabel. shadowColor = [UIColor redColor];
ScoreLabel. shadowOffset = CGSizeMake (1.0, 1.0 );
// Set whether to interact with the user
ScoreLabel. userInteractionEnabled = YES;
// Set whether the text in the label is variable. The default value is YES.
ScoreLabel. enabled = NO;
// Set the display format when the text is too long
ScoreLabel. lineBreakMode = UILineBreakModeMiddleTruncation; // intercept
The following formats can be displayed in the definition:
// Typedef enum {
// UILineBreakModeWordWrap = 0,
// UILineBreakModeCharacterWrap,
// UILineBreakModeClip, // cut the excess part
// UILineBreakModeHeadTruncation, // capture the header
// UILineBreakModeTailTruncation, // remove the tail
// UILineBreakModeMiddleTruncation, // intercept
//} UILineBreakMode;
// If the adjustsFontSizeToFitWidth attribute is set to YES, this attribute controls the behavior of the text baseline.
ScoreLabel. baselineAdjustment = UIBaselineAdjustmentNone;
The following formats can be displayed in the definition:
// Typedef enum {
// UIBaselineAdjustmentAlignBaselines,
// UIBaselineAdjustmentAlignCenters,
// UIBaselineAdjustmentNone,
//} UIBaselineAdjustment;
// Set the background color to transparent
ScoreLabel. backgroudColor = [UIColor clearColor];
You can also use custom colors:
UIColor * color = [UIColor colorWithRed: 1.0f green: 50366f blue: 0.0f alpha: 1.0f];
ScoreLabel. textColor = [UIColor color];
// The RGB value in UIColor is of the CGFloat type ranging from 0 ~ The value ranges from 0 to 1 ~ The color value range of 255.
Ii. UITextField
(1) initialize UITextField
UITextField * text = [[UITextField alloc] initWithFrame: CGRectMake (10, 50,300, 30)];
Text. borderStyle = UITextBorderStyleRoundedRect;
Text. autocorrectionType = UITextAutocorrectionTypeYes;
Text. placeholder = @ "Hello, I'm Andy-Qingfeng ";
Text. returnKeyType = UIReturnKeyDone;
Text. clearButtonMode = UITextFieldViewModeWhileEditing;
[Text setBackgroundColor: [UIColor whiteColor];
Text. delegate = self;
[Self. view addSubview: text];
(2) detailed parameter explanation
BorderStyle: border style of the text box www.2cto.com
AutocorrectionType: You can set whether to enable the automatic reminder correction function.
Placeholder: Set the default text display.
ReturnKeyType: Specifies the keyboard completion button.
BackgroundColor: Set the background color.
Delegate: Set Delegation
(3) delegate Method
-(Void) textFieldDidBeginEditing :( UITextField *) textField;
// The method that will be called when textField is clicked
-(Void) textFieldDidEndEditing :( UITextField *) textField;
// Method called when textField editing ends
// Press the call method of the Done button to make the keyboard disappear
-(BOOL) textFieldShouldReturn :( UITextField *) textField {
[TextField resignFirstResponder];
Return YES;
}
Today we will introduce UILabel and UITextField. Next we will talk about UIImageView and UIWebView. Thank you for your support.
From Andy --- breeze