我正在尝试向 UITableView 添加页脚。该表是一个评论表,页脚是用户输入他/她的评论以发表的地方。所以很自然地,我定义了一个 UIView 并在 UIView 中添加了一个 UITextField 和一个 UIButton。 (左到右)。
问题是 UIView 没有包含 subview 。我希望 child 在父页脚内垂直居中。我的代码如下。我究竟做错了什么?现在父 View 显示为红色的薄板。与父级重叠的是 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;
}
最佳答案
将clipsToBounds设置为YES
footer.clipsToBounds = YES;
相关文档:
A Boolean value that determines whether subviews are confined to the bounds of the view.
Declaration SWIFT var clipsToBounds: Bool OBJECTIVE-C @property(nonatomic) BOOL clipsToBounds Discussion Setting this value to YES causes subviews to be clipped to the bounds of the receiver. If set to NO, subviews whose frames extend beyond the visible bounds of the receiver are not clipped. The default value is NO.
Import Statement import UIKit
Availability Available in iOS 2.0 and later.
要调整页脚的大小,您必须覆盖页脚高度的 UITableViewDelegate 方法:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section Parameters tableView The table-view object requesting this information. section An index number identifying a section of tableView . Return Value A nonnegative floating-point value that specifies the height (in points) of the footer for section.
关于ios - 父 UIView 不包含/剪辑 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26028137/
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我有一个包含多个键的散列和一个字符串,该字符串不包含散列中的任何键或包含一个键。h={"k1"=>"v1","k2"=>"v2","k3"=>"v3"}s="thisisanexamplestringthatmightoccurwithakeysomewhereinthestringk1(withspecialcharacterslike(^&*$#@!^&&*))"检查s是否包含h中的任何键的最佳方法是什么,如果包含,则返回它包含的键的值?例如,对于上面的h和s的例子,输出应该是v1。编辑:只有字符串是用户定义的。哈希将始终相同。 最佳答案
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
我的Gallery模型中有以下查询:media_items.includes(:photo,:video).rank(:position_in_gallery)我的图库模型有_许多媒体项,每个都有一个照片或视频关联。到目前为止,一切正常。它返回所有media_items包括它们的photo或video关联,由media_item的position_in_gallery属性排序。但是我现在需要将此查询返回的照片限制为仅具有is_processing属性的照片,即nil。是否可以进行相同的查询,但条件是返回的照片等同于:.where(photo:'photo.is_processingIS
-if!request.path_info.include?'A'%{:id=>'A'}"Text"-else"Text"“文本”写了两次。我怎样才能只写一次并同时检查path_info是否包含“A”? 最佳答案 有两种方法可以做到这一点。使用部分,或使用content_forblock:如果“文本”较长,或者是一个重要的子树,您可以将其提取到一个部分。这会使您的代码变干一点。在给出的示例中,这似乎有点矫枉过正。在这种情况下更好的方法是使用content_forblock,如下所示:-if!request.path_info.inc
Ocra无法处理需要“tk”的应用程序require'tk'puts'nope'用奥克拉http://github.com/larsch/ocra不起作用(如链接中的一个问题所述)问题:https://github.com/larsch/ocra/issues/29(Ocra是1.9的"new"rubyscript2exe,本质上它用于将rb脚本部署为可执行文件)唯一的问题似乎是缺少tcl的DLL文件我不认为这是一个问题据我所知,问题是缺少tk的DLL文件如果它们是已知的,则可以在执行ocra时将它们包括在内有没有办法知道tk工作所需的DLL依赖项? 最佳答
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上
我正在使用DMOZ的listofurltopics,其中包含一些具有包含下划线的主机名的url。例如:608609TheOuterHeaven610InformationandimagegalleryofMcFarlane'sactionfiguresforTrigun,Akira,TenchiMuyoandotherJapaneseSci-Fianimations.611Top/Arts/Animation/Anime/Collectibles/Models_and_Figures/Action_Figures612虽然此url可以在网络浏览器中使用(或者至少在我的浏览器中可以使用: