如何使用我在.nib
文件中的图像上添加的按钮放大和缩小?我可以缩放图像,但模拟器上的运行时间不显示按钮。
我使用以下代码进行缩放:
i do what u say in the view did load and here is the code
- (void)viewDidLoad {
[super viewDidLoad];
self.visiblePopTipViews = [NSMutableArray array];
self.contents = [NSDictionary dictionaryWithObjectsAndKeys:
// Rounded rect buttons
@"Play Ground", [NSNumber numberWithInt:1],
@"HeadMaster", [NSNumber numberWithInt:2],
@"Science Faculty", [NSNumber numberWithInt:3],
@"Accounting Faculty", [NSNumber numberWithInt:4],
@"Economy Faculty", [NSNumber numberWithInt:5],
@"Cultive Faculty", [NSNumber numberWithInt:6],
@"Tourisim Faculty", [NSNumber numberWithInt:7],
@"Swimming Pool ", [NSNumber numberWithInt:8],
@"Medicine Faculty", [NSNumber numberWithInt:9],
@"Engeneering Faculty", [NSNumber numberWithInt:10],
@"IT Faculty", [NSNumber numberWithInt:11],
nil];
// Array of (backgroundColor, textColor) pairs.
// NSNull for either means leave as default.
// A color scheme will be picked randomly per CMPopTipView.
self.colorSchemes = [NSArray arrayWithObjects:
[NSArray arrayWithObjects:[NSNull null], [NSNull null], nil],
[NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil],
[NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil],
[NSArray arrayWithObjects:[UIColor lightGrayColor], [UIColor darkTextColor], nil],
[NSArray arrayWithObjects:[UIColor lightGrayColor], [UIColor blueColor], nil],
[NSArray arrayWithObjects:[UIColor lightGrayColor], [NSNull null], nil],
nil];
scroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
scroll.backgroundColor = [UIColor blackColor];
scroll.delegate = self;
zoomView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, scroll.contentSize.width, scroll.contentSize.height)];
zoomView.backgroundColor = [UIColor whiteColor];
image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map.png"]];
scroll.contentSize = image.frame.size;
UIButton *playGround = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[playGround addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[playGround setTitle:@"playGround" forState:UIControlStateNormal];
playGround.tag = 1 ;
playGround.frame = CGRectMake(290.0, 170.0, 80.0, 40.0);
[image addSubview:playGround];
UIButton *masterBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[masterBtn addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[masterBtn setTitle:@"Presidency" forState:UIControlStateNormal];
masterBtn.tag = 2 ;
masterBtn.frame = CGRectMake(250.0, 270.0, 60.0, 30.0);
[image addSubview:masterBtn];
UIButton *scienceBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[scienceBtn addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[scienceBtn setTitle:@"science" forState:UIControlStateNormal];
scienceBtn.tag = 3;
scienceBtn.frame = CGRectMake(300.0, 330.0, 50.0, 30.0);
[image addSubview:scienceBtn];
UIButton *accountingBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[accountingBtn addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[accountingBtn setTitle:@"Accounting" forState:UIControlStateNormal];
accountingBtn.tag = 4;
accountingBtn.frame = CGRectMake(340.0, 360.0, 50.0, 30.0);
[image addSubview:accountingBtn];
UIButton *economyBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[economyBtn addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[economyBtn setTitle:@"Economy" forState:UIControlStateNormal];
economyBtn.tag = 5 ;
economyBtn.frame = CGRectMake(390.0, 390.0, 50.0, 30.0);
[image addSubview:economyBtn];
UIButton *cultiveBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[cultiveBtn addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[cultiveBtn setTitle:@"Cultive" forState:UIControlStateNormal];
cultiveBtn.tag = 6 ;
cultiveBtn.frame = CGRectMake(440.0, 410.0, 50.0, 30.0);
[image addSubview:cultiveBtn];
UIButton *tourisimBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[tourisimBtn addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[tourisimBtn setTitle:@"tourisim" forState:UIControlStateNormal];
tourisimBtn.tag = 7 ;
tourisimBtn.frame = CGRectMake(480.0, 440.0, 50.0, 30.0);
[image addSubview:tourisimBtn];
UIButton *swimmingBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[swimmingBtn addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[swimmingBtn setTitle:@"swimming" forState:UIControlStateNormal];
swimmingBtn.tag = 8 ;
swimmingBtn.frame = CGRectMake(190.0, 400.0, 50.0, 30.0);
[image addSubview:swimmingBtn];
UIButton *medicineBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[medicineBtn addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[medicineBtn setTitle:@"medicine" forState:UIControlStateNormal];
medicineBtn.tag = 9;
medicineBtn.frame = CGRectMake(250.0, 420.0, 70.0, 30.0);
[image addSubview:medicineBtn];
UIButton *enegeneeringBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[enegeneeringBtn addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[enegeneeringBtn setTitle:@"engeneering" forState:UIControlStateNormal];
enegeneeringBtn.tag = 10 ;
enegeneeringBtn.frame = CGRectMake(340.0, 460.0, 60.0, 30.0);
[image addSubview:enegeneeringBtn];
UIButton *itBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[itBtn addTarget:self
action:@selector(buttonAction:)
forControlEvents:UIControlEventTouchDown];
[itBtn setTitle:@"It" forState:UIControlStateNormal];
itBtn.tag = 11 ;
itBtn.frame = CGRectMake(410.0, 500.0, 60.0, 30.0);
[image addSubview:itBtn];
[zoomView addSubview:image ] ;
[scroll addSubview:zoomView];
[scroll bringSubviewToFront:zoomView ] ;
// [self.view addSubview:scroll ] ;
scroll.minimumZoomScale =scroll.frame.size.width / image.frame.size.width;
scroll.maximumZoomScale = 2.0;
[scroll setZoomScale:scroll.minimumZoomScale];
self.view = scroll;
[scroll release];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return image ;
}
答案 0 :(得分:0)
这个loadView方法在你的View Controller上,不是吗? 当View Controller需要加载其视图时,将调用此方法。如果您将按钮添加到nib文件中,并且正在调用此方法,则按钮将不会显示 - 它正在加载您的代码,而不是您的笔尖。
您应该做的是将UIScrollView添加为子视图,或者在nib文件中添加更多内容。 如果您确实执行了代码,请确保不要覆盖self.view,但要为其添加子视图。在viewDidLoad中执行此操作,而不是loadView。
这样做,你的按钮就会显示出来。