IOS UI controls Modify location and dimensions, code add controls

Source: Internet
Author: User

All UI controls are ultimately inherited from the public properties of the Uiview,ui control are defined in UIView,UIViewCommon Properties ofUIView *superview; Get your own parent control objectNsarray *subviews; Get all of your child control objects Nsinteger tag; The ID (identity) of the control, and the parent control can find the corresponding child control via tag Cgaffinetransform transform;the deformation properties of the control (you can set the rotation angle, scale, pan, and other properties)CGRect frame;position and dimensions of the control's rectangle in the parent control (the origin of the coordinates in the upper-left corner of the parent control)CGRect bounds;The position and dimensions of the rectangle where the control is located (the origin of the coordinates in its upper-left corner, so bounds X, Y is generally 0)Cgpoint Center; The position of the midpoint of the control, in the upper-left corner of the parent control, as the coordinate origin. Common button statesNormal (normal state)Enumeration constants corresponding to default: UIControlStateNormal

highlighted (highlight state)When the button is pressed (the finger is not released) the corresponding enumeration constant: uicontrolstatehighlighteddisabled (fail State, unavailable state)If the Enabled property is no, it is in the disable state, which means that the button cannot be clicked on the corresponding enumeration constant: Uicontrolstatedisabled different states, you can set the button different properties (color, text, background image, etc.) to modify the position of the control You can modify the position and dimensions of the control on the screen by modifying the control's Frame property to modify the position of the control by using the following properties Frame.origincenter

You can modify the size of a control by using the Frame.sizebounds.size property?
1 2 3 4 5 6 7 8 9 // 比如点击“向上”按钮,让按钮的y值减小即可 - (IBAction)top:(UIButton *)sender {     CGRect btnFrame = self.headBtn.frame;     btnFrame.origin.y -= 10;     self.headBtn.frame = btnFrame; }   // 下面代码是错误的,OC语法规定:不允许直接修改对象的结构体属性的成员self.headBtn.frame.origin.y -= 10;

Pass

Property can modify the position of the control, the size does not need to calculate the result after the deformation

Code Add control

?
1 2 3 4 5 6 7 8 // 创建一个自定义的按钮 UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; // 默认状态的背景 [btn setBackgroundImage:[UIImage imageNamed:@"btn_01"] forState:UIControlStateNormal]; // 默认状态的文字 [btn setTitle:@"点我啊" forState:UIControlStateNormal]; // 默认状态的文字颜色(有哪些颜色可以直接点UIColor头文件查看)[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

For example:

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 // 视图加载完成调用的方法,通常视图控制器的初始化工作,在此执行! // 一定不要忘记调用父类的实现方法 - (void)viewDidLoad // 此方法是继承自父类的方法 {     [super viewDidLoad];       // 创建按钮控件     UIButton *btn = [[UIButton alloc] init];     // 设置控件的位置    btn.frame = CGRectMake(20, 20, 100, 100);     // btn.backgroundColor = [UIColor redColor];     // 设置控件的文字    [btn setTitle:@"按钮" forState:UIControlStateNormal];     // 设置控件文字的颜色    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];         UIImage *image = [UIImage imageNamed:@"btn_01"];     [btn setBackgroundImage:image forState:UIControlStateNormal];     [btn setTitle:@"点我" forState:UIControlStateNormal];   // 设置按钮控件在普通状态下的字体颜色     [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];     // 设置按钮空间在高粱状态下的背景图片     [btn setBackgroundImage:[UIImage imageNamed:@"btn_02"] forState:UIControlStateHighlighted];       // 将设置好的按钮空间添加到当前view中    [self.view addSubview:btn];         // 按钮的监听方法     [btn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];       // 将.h中声明的属性headImageView与btn相关联     self.headImageView = btn; }

  

Modify the size. Angle

?
1 2 3 4 5 6 7     // MakeTranslation是基于对象初始位置做的形变 //    self.delta -= 20; //    NSLog(@"%d", self.delta); //    self.headImageView.transform = CGAffineTransformMakeTranslation(0, self.delta);     // Translate是基于transform参数做的形变,实际效果就是一个累加的位移效果       self.headImageView.transform = CGAffineTransformTranslate(self.headImageView.transform, 0, -20);       self.headImageView.transform = CGAffineTransformScale(self.headImageView.transform, 2.0, 1.0);

In OC, all values associated with the angle are in radians, 180°= M_PI
Positive number indicates clockwise rotation
Negative number indicates counterclockwise rotation
Self.headImageView.transform = Cgaffinetransformrotate (Self.headImageView.transform,-m_pi_4);

  

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.