码迷,mamicode.com
首页 > 其他好文 > 详细

UITextfiled子视图被剪切

时间:2016-04-06 14:53:31      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

一般情况下,如果在view1上面添加了view2,但是view2超出了view1,也会在屏幕上面显示超出的部分

例如:

UIButton *button =[[UIButton alloc]initWithFrame:CGRectMake(100, 400, 120, 30)];
[self.view addSubview:button];
UIButton * btn1 = [[UIButton alloc]initWithFrame:CGRectMake(button.frame.size.width-5, -5, 10, 10)];
btn1.backgroundColor = [UIColor redColor];
[button addSubview:btn1];
button.backgroundColor = [UIColor grayColor];
显示结果如下(图一)

但是如果是UItextfiled,那么就会默认的剪切掉超出textfiled的部分

例如:

  UITextField * filed = [[UITextField alloc]initWithFrame:CGRectMake(100, 200, 120, 30)];
    [self.view addSubview:filed];
    filed.borderStyle = UITextBorderStyleRoundedRect;
    UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(filed.frame.size.width-5, -5, 10, 10)];
    [filed addSubview:btn];
    btn.backgroundColor = [UIColor redColor];
    self.view.backgroundColor = [UIColor whiteColor];

显示结果图二

技术分享(图一)技术分享(图二)技术分享

这个造成的原因是uitextfiled会默认的在layer层给超出父控件的给剪切掉,解决方法如下

filed.layer.masksToBounds = NO

显示结果如图三

 

UITextfiled子视图被剪切

标签:

原文地址:http://www.cnblogs.com/fusheng-it/p/5359029.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!