调整的UIView不工作

我有我从一个视图控制器调用UIView子类。 它显示了一切,但我无法调整其大小。 当我把一个断点视图的initwithframe方法,它显示了不变,但视图控制器是绝对改变它...

下面是我的视图控制器的代码:

- (void)resizeWithTag:(int)tag wasTouched:(BOOL)touched { GameBox *tbox = (GameBox *)[self.view viewWithTag:tag]; CGRect frame = tbox.frame; frame = CGRectMake(0, 0, 300, 300); tbox.frame = frame; [tbox setNeedsDisplay]; NSLog(@"%f", tbox.frame.size.width); }

这里是init方法并绘制UIView子类的方法

- (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code [self setBackgroundColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]]; name = [[UILabel alloc] init]; self.autoresizesSubviews = YES; } return self; } // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code int border = 3; UIImage *image = [UIImage imageNamed:@"Sunflower.jpeg"]; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBStrokeColor(context, 0.0, 0.0, 0.0, 1); CGContextStrokeRectWithWidth(context, CGRectMake(0, 0, rect.size.width, rect.size.height), border); [self attachImage:image inRect:rect inBorder:border]; [name setFrame:CGRectMake(0 + border/2, rect.size.height-10-border/2, rect.size.width-(border), 10)]; [name setFont:[UIFont fontWithName:@"Helvetica" size:9.0]]; [name setBackgroundColor:[UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.0]]; name.textAlignment = UITextAlignmentCenter; [self addSubview:name]; }

--------------解决方案-------------

投入断点initWithFrame:是不是要寻找正确的地方。 在创建视图将其称为一次。

后来你抓住的看法,改变它的frame属性通过调用tbox.frame = someFrame相当于调用setFrame:

这条线

NSLog(@"%f", tbox.frame.size.width);

应该说明你做了更改宽度。

分类:iphone 时间:2013-01-15 人气:0
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.177 (s). 9 q(s)