Kat*_*lon 2 footer uitableview uiview addsubview ios
我试图在UITableView中添加页脚.该表是评论表,页脚是用户输入他/她的评论以进行发布的位置.所以当然,我定义了一个UIView,在UIView中,我添加了一个UITextField和一个UIButton.(左到右).
问题是UIView没有包含儿童观点.我希望孩子们在父页脚内垂直居中.我的代码如下.我究竟做错了什么?现在,父视图显示为红色的薄板.与父级重叠的是UITextField和UIButon,它们的高度比父级高.
- (UIView *)tableView:(UITableView *)tv viewForFooterInSection:(NSInteger)section
{
static UIView *footer =nil;
if (nil == footer) {
footer =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 70)];
footer.backgroundColor=[UIColor redColor];
self.commentInputTextView=[[UITextView alloc]initWithFrame:CGRectMake(0, 0, 240, 50)];
self.commentInputTextView.delegate=self;
self.commentInputTextView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
self.commentInputTextView.backgroundColor=[UIColor greenColor];
[footer addSubview:self.commentInputTextView];
UIButton *post = [[UIButton alloc] initWithFrame:CGRectMake(250, 0, 60, 50)];
post.backgroundColor=[UIColor blueColor];
[post setTitle:@"Post" forState:UIControlStateNormal];
[footer addSubview:post];
[footer sizeToFit];
}
return footer;
}
Run Code Online (Sandbox Code Playgroud)
设为clipsToBounds
是
footer.clipsToBounds = YES;
Run Code Online (Sandbox Code Playgroud)
关于这个的文件:
一个布尔值,用于确定子视图是否仅限于视图的边界.
声明SWIFT var clipsToBounds:Bool OBJECTIVE-C @property(非原子)BOOL clipsToBounds讨论将此值设置为YES会导致子视图被剪切到接收器的边界.如果设置为NO,则不会剪切其帧超出接收器可见边界的子视图.默认值为NO.
Import Statement导入UIKit
可用性适用于iOS 2.0及更高版本.
要调整页脚大小,您必须覆盖UITableViewDelegate
页脚高度的方法:
- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section参数tableView请求此信息的表视图对象.section标识tableView部分的索引号.返回值一个非负浮点值,指定页脚的高度(以磅为单位).
归档时间: |
|
查看次数: |
4738 次 |
最近记录: |