首页 > 其他 > 详细

UITextfiled子视图被剪切

时间:2016-04-06 14:51:09      阅读:240      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!