我有一些问题。我想在滚动视图中显示静态和动态对象。我有 IBOutlets,它们是连接的。我想更改消息和标题,它们是在代码中手动创建的。所有其他对象都是静态的。我的代码在这里:
.h 文件:
@interface MessageContentViewController (){
IBOutlet UIImageView *avatarImageView;
IBOutlet UIScrollView *scrollView;
IBOutlet UIImageView *msgBoardImg;
IBOutlet UIImageView *topBarImg;
IBOutlet UIButton *backBtn;
NSMutableArray *allMessages;
}
@property int indexOfMsg;
@end
.m 文件:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]]];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[scrollView setContentSize:CGSizeMake(scrollView.frame.size.width * allMessages.count, 0)];
[scrollView setPagingEnabled:YES];
[scrollView scrollRectToVisible:CGRectMake(scrollView.frame.size.width * indexOfMsg, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height) animated:NO];
for (int i = 0; i < allMessages.count; i++) {
UIView *tempSubView = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width * i, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
[tempSubView addSubview:topBarImg];
[tempSubView addSubview:backBtn];
[tempSubView addSubview:msgBoardImg];
[tempSubView addSubview:avatarImageView];
[scrollView addSubview:tempSubView];
}
[scrollView setContentOffset: CGPointMake(scrollView.frame.size.width * indexOfMsg, 0)];
CGRect currentViewFrame = CGRectMake(scrollView.frame.size.width * indexOfMsg, scrollView.frame.origin.y, scrollView.frame.size.width, scrollView.frame.size.height);
[scrollView scrollRectToVisible:currentViewFrame animated:NO];
}
.xib 文件:
请帮我。提前致谢。