iOS - control view, button

IBAction and IBOutlet

IBAction is the return value, equivalent to void. Only when the return value is the method of IBAction, can the control in the storyboard be connected

Only properties declared as iboutlets can be wired to controls in the storyboard

In order to ensure that the control is not modified by other places and becomes a private variable, it is declared in the. m file

The reason for using weak is that there is already a strong pointer to it

UIView

  • Controls: all UI elements on the screen are called controls
  • Attributes: size, position, background color

    Common properties are extracted into UIView

  • Every control is a container. UIVIew is the most common container
    • The controller is invisible
    • Each controller has a UIVIew
    • What you can see is View
    • Each controller has a UIVIew attribute
    • All child controls managed in the controller are child controls of the space

Common methods

// Add a child control view
- (void)addSubview:(UIVIew *)view;
// Remove yourself from the parent control
- (void)removeFromSuperview;
// Find out a corresponding control (usually a child control) according to a tag identifier
- (UIView *)viewWithTag:(NSInteger)tag;

Common attributes

// The position and size of the control rectangle in the parent control, with the upper left corner as the coordinate origin
@property(nonatomic) CGRect frame;
label.frame = CGRectMake(0, 0, 100, 100);

// Modify method 1
self.label.frame = CGRectMake(200, 100, 100, 50);
// Modification method 2
// Struct is value passing, not address passing
CGRect frame = self.label.frame;
frame.origin.x -= 100;
frame.size.width += 50;
self.label.frame = frame;
// The position and size of the control rectangle box, with its upper left corner as the coordinate origin, and the x and y of the borders are generally 0
@property(nonatomic) CGRect bounds;
//Control midpoint position
@property(nonatomic) CGPoint    center; 

viewDidLoad

/**
 1. system call
 2. Called when the View of the controller is loaded
 3. Control initialization, data initialization (lazy loading)
 */
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

didReceiveMemoryWarning

/**
 1. system call
 2. When the controller receives a memory warning call
 3. Take out some unnecessary memory, take out the time-consuming memory
 */
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

Button

Button event

- (IBAction)clickRedButton
{
    // Change text color
    self.label.textColor = [UIColor redColor];
    // Change text content
    self.label.text = @"I am red.";
    // Change text background color
    self.label.backgroundColor = [UIColor greenColor];
    // Change text alignment NSTextAlignmentCenter: Center, NSTextAlignmentRight: right, NSTextAlignmentLeft: left
    self.label.textAlignment = NSTextAlignmentCenter;
    // Change text size
    self.label.font = [UIFont systemFontOfSize:30.f];
}

Tags: Attribute

Posted on Sat, 04 Apr 2020 18:17:27 -0700 by jeff_valken