이 질문은 여기에 많이 있지만, 여전히 작동하지 않는 것 같습니다. 아마 올바르게 또는 뭔가보기를 시작하지 않을거야 ... 어쨌든, 나는 UIScrollView에 프로그래밍 방식으로 여러 레이블과 이미지를 추가하려고합니다.프로그래밍 방식으로 UIScrollView에 UILabels 및 UIImageViews 추가
#import <UIKit/UIKit.h>
@interface DOR_HelpViewController : UIViewController <UIScrollViewDelegate> {
IBOutlet UIScrollView *scrollView;
}
@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
@end
그리고 내하는 .m 파일 :
#import "DOR_HelpViewController.h"
@implementation DOR_HelpViewController
@synthesize scrollView;
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
scrollView = [[UIScrollView alloc] init];
UILabel *pointsCouponLbl = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 20.0, 320.0, 15.0)];
pointsCouponLbl.font = [UIFont boldSystemFontOfSize:14.0];
pointsCouponLbl.textAlignment = UITextAlignmentCenter;
pointsCouponLbl.textColor = [UIColor blackColor];
pointsCouponLbl.backgroundColor = [UIColor clearColor];
pointsCouponLbl.text = @"Points Earned Using a Coupon";
[scrollView addSubview:pointsCouponLbl];
UIImageView *pointsCouponImg = [[UIImageView alloc] initWithFrame:CGRectMake(72, 45, 175, 100)];
pointsCouponImg.image = [UIImage imageNamed:@"couponpoints.png"];
[scrollView addSubview:pointsCouponImg];
UILabel *pointsCheckInLbl = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 165.0, 320.0, 15.0)];
pointsCheckInLbl.font = [UIFont boldSystemFontOfSize:14.0];
pointsCheckInLbl.textAlignment = UITextAlignmentCenter;
pointsCheckInLbl.textColor = [UIColor blackColor];
pointsCheckInLbl.backgroundColor = [UIColor clearColor];
pointsCheckInLbl.text = @"Points Earned For Check-In";
[scrollView addSubview:pointsCheckInLbl];
pointsCheckInLbl = nil;
UIImageView *pointsCheckInImg = [[UIImageView alloc] initWithFrame:CGRectMake(72, 190, 175, 100)];
pointsCheckInImg.image = [UIImage imageNamed:@"checkinpoints.png"];
[scrollView addSubview:pointsCheckInImg];
pointsCheckInImg = nil;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
scrollView
은 내 스토리 보드 내 UIScrollView
객체에 연결되어 여기 내 .H 파일에 대한 내 코드입니다. 나는 내가 잘못하고있는 것에 대한 정보를 매우 감사 할 것이고, 만약 당신이 신경 쓰지 않는다면 왜 그렇게 할 것인가. 미리 감사드립니다 ~
, 그러나 확신하는 당신이 IB에 정의 된 뷰를 할당/초기화해야합니까? 즉,'scrollView = [[UIScrollView alloc] init];'필요한가? –
아니요, 확실하지 않습니다. 내가 그것을 시험해보아야했기 때문에 그것이 내가 고려하고 있었던 것들 중 하나이기 때문이다. 그걸 답으로 써 주시겠습니까? 방금 제거하고 작동했습니다. – James
게시 됨 내 대답! –