我有一个视图(myView),并且由于 myView 上的显示文本而在 myView 上创建了一些标签。我在 myView 上应用了 pinchgesturerecognizer。它工作得很好。我的问题是当我在 myView 上捏时,标签文本的大小将根据捏的增加或减少而改变。如果你捏(放大)myView,标签文本的大小非常小,所以我们看不到文本。如果你捏(缩小)myView,标签文本的大小很大。
因此,无论您放大或缩小 myView,我都想修复标签文本的大小。我试过了,但我没有得到答案。我也用过setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth
,但没看懂。我不知道如何使用它。请帮我。提前致谢。
我的代码是:
在ViewController.m
,
- (void)viewDidLoad
{
MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(0, 100, 200, 100)];
[self.view addSubview:myView];
[super viewDidLoad];
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scalePiece:)];
[pinchGesture setDelegate:self];
[myView addGestureRecognizer:pinchGesture];
[pinchGesture release];
}
- (void)scalePiece:(UIPinchGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] == UIGestureRecognizerStateChanged) {
[gestureRecognizer view].transform = CGAffineTransformScale([[gestureRecognizer view] transform], [gestureRecognizer scale], [gestureRecognizer scale]);
//[gestureRecognizer setScale:1];
}
}
在MyView.m
,
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 35, 20)];
label1.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
label1.text = @"label1";
[self addSubview:label1];
label2 = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 35, 20)];
label2.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
label2.text = @"label2";
[self addSubview:label2];
label3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, 35, 20)];
label3.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
label3.text = @"label1";
[self addSubview:label3];
label4 = [[UILabel alloc] initWithFrame:CGRectMake(40, 40, 35, 20)];
label4.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
label4.text = @"label4";
[self addSubview:label4];
}
return self;
}
我想修复 label1、label2、label3、label4 的文本。