我有一个 tableViewHeader UIView,其中包含一些动态元素(准确地说是大小不一的 UILabel)。我在 IB 中设置了 UIView,连接了所有内容,并尝试根据 sizeToFit 之后的标签大小更改框架原点。
如果我在 setFrame 调用后记录新帧,它实际上会显示更新的来源,但它们不会显示在模拟器上。标签改变高度,但原点不变。
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect frame;
CGFloat baseOffset = titleLbl.frame.origin.y;
offset = titleLbl.frame.size.height;
self.titleLbl.text = destObject.title;
self.titleLbl.font = [UIFont fontWithName:@"Avenir-Heavy" size:22];
[self.titleLbl sizeToFit];
frame = titleLbl.frame;
frame.origin.y = baseOffset;
//Get any change in size from the label
offset = titleLbl.frame.size.height - offset;
frame = imageView.frame;
frame.origin.y = frame.origin.y + offset;
self.imageView.frame = frame;
frame = photosBtn.frame;
frame.origin.y = frame.origin.y + offset;
[self.photosBtn setFrame:frame];
frame = detailLbl.frame;
frame.origin.y = frame.origin.y + offset;
self.detailLbl.frame = frame;
baseOffset = self.detailLbl.frame.origin.y;
CGFloat detailOffset = self.detailLbl.frame.size.height;
self.detailLbl.text = destObject.description;
[self.detailLbl sizeToFit];
frame = detailLbl.frame;
frame.origin.y = baseOffset;
self.detailLbl.frame = frame;
detailOffset = self.detailLbl.frame.size.height - detailOffset;
offset = offset + detailOffset;
frame = blueLine.frame;
frame.origin.y = frame.origin.y + offset;
self.blueLine.frame = frame;
self.whereToDiveLbl.font = [UIFont fontWithName:@"Avenir-Heavy" size:22];
frame = whereToDiveLbl.frame;
frame.origin.y = frame.origin.y + offset;
self.whereToDiveLbl.frame = frame;
frame = grayLine.frame;
frame.origin.y = frame.origin.y + offset;
self.grayLine.frame = frame;
frame = CGRectMake(headerView.frame.origin.x, headerView.frame.origin.y, headerView.frame.size.width, grayLine.frame.size.height + grayLine.frame.origin.y + 5);
self.headerView.frame = frame;
}
我曾尝试四处寻找类似的问题,但找不到任何问题。任何人都可以阐明这一点吗?
我应该指出,UIView 本身(即本例中的 headerView)确实会反射(reflect)模拟器上对其框架的更改,但其 subview 不会。如果它有任何不同,我会启用自动调整 subview 大小,但启用或禁用我得到相同的结果。
最佳答案
我发现我在 IB 中的 UIView 在身份和类型下选中了“使用自动布局”...取消选择它解决了我的问题。
关于ios - tableViewHeader 的 subview 上的 setFrame 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12570958/
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems
我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que
这里有一个很好的答案解释了如何在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使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
我有一个.pfx格式的证书,我需要使用ruby提取公共(public)、私有(private)和CA证书。使用shell我可以这样做:#ExtractPublicKey(askforpassword)opensslpkcs12-infile.pfx-outfile_public.pem-clcerts-nokeys#ExtractCertificateAuthorityKey(askforpassword)opensslpkcs12-infile.pfx-outfile_ca.pem-cacerts-nokeys#ExtractPrivateKey(askforpassword)o
我目前正在尝试学习RubyonRails和测试框架RSpec。assigns在此RSpec测试中做什么?describe"GETindex"doit"assignsallmymodelas@mymodel"domymodel=Factory(:mymodel)get:indexassigns(:mymodels).shouldeq([mymodel])endend 最佳答案 assigns只是检查您在Controller中设置的实例变量的值。这里检查@mymodels。 关于ruby-o
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上