Eye*_*all 2 cocoa-touch interface-builder xib ios
我正在尝试更改我从xib加载的自定义视图的框架.
这是我的视图的init方法:
- (id)initWithUserName:(NSString*)userName andComment:(NSString*)comment
{
if (self) {
self = [[[NSBundle mainBundle] loadNibNamed:@"Comment" owner:self options:nil]objectAtIndex:0];
self.userName = userName;
self.comment = comment;
NSLog(@"CREATED");
NSLog(@"%@, %@",self.userName, self.comment);
self.userNameButton.tag = -1;
CGSize constraint = CGSizeMake(240, 2000);
self.userNameButton.backgroundColor = [UIColor clearColor];
CGSize sizeOfUsernameText = [self.userName sizeWithFont:[UIFont fontWithName:@"OpenSans-Light" size:12.0] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
//color converted from #161616 Hex
[self.userNameButton.titleLabel setTextColor:[StaticMethods colorFromHexString:@"#161616"]];
[self.userNameButton setTitle:[self.userName stringByAppendingString:@":"] forState:UIControlStateNormal];
[self.userNameButton.titleLabel setFont:[UIFont fontWithName:@"OpenSans-Light" size:12.0]];
[self.userNameButton setNeedsDisplay];
//[self.userNameButton addTarget:self.delegate action:@selector(userNameButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
//Append appropriate amount so that the usernames can be seen and clickable
NSString *indentString = @" ";
CGSize sizeOfWhitespaces = [indentString sizeWithFont:[UIFont fontWithName:@"OpenSans-Light" size:12.0] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
while (sizeOfWhitespaces.width < sizeOfUsernameText.width) {
sizeOfWhitespaces = [indentString sizeWithFont:[UIFont fontWithName:@"OpenSans-Light" size:12.0] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
indentString = [indentString stringByAppendingString: @" "];
}
CGSize sizeOfComment = [comment sizeWithFont:[UIFont fontWithName:@"OpenSans-Light" size:12.0] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
self.commentText.tag = -1;
self.commentText.text = [indentString stringByAppendingString: self.comment];
self.commentText.font = [UIFont fontWithName:@"OpenSans-Light" size:12.0];
[self.commentText setTextColor:[StaticMethods colorFromHexString:@"#161616"]];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
从这样的视图控制器调用此方法:
- (void)viewDidLoad
{
[super viewDidLoad];
for(int i = 0; i < self.userNames.count;i++){
CommentView *view = [[CommentView alloc]initWithUserName:[self.userNames objectAtIndex:i] andComment:[self.comments objectAtIndex:i]];
[view setDelegate: self];
[self.view addSubview:view];
view.frame = CGRectMake(0,100,320,100);
}
// Do any additional setup after loading the view from its nib.
}
Run Code Online (Sandbox Code Playgroud)
现在,它所说的行view.frame = CGRectMake(0,100,320,100);是我试图改变视图框架的地方.我已经尝试将该代码放在视图中
- (id)initWithUserName:(NSString*)userName andComment:(NSString*)comment
方法体也没有运气.
很明显,我无法根据自己的喜好调整视图大小.视图始终与界面构建器中显示的帧相同.
我究竟做错了什么?
编辑
我已经尝试将上面的viewDidLoad主体放在viewcontroller的viewWillAppear主体内,没有任何进展.
| 归档时间: |
|
| 查看次数: |
5634 次 |
| 最近记录: |