gpt4 book ai didi

iphone - 如何调整 iPhone 中按钮图像的大小

转载 作者:行者123 更新时间:2023-12-03 21:08:58 26 4
gpt4 key购买 nike

我是 iphone 的新用户。现在我正在 iphone 中开发按钮 ImageView 。这里的图像是显示大尺寸的图像,我想调整图像的大小。这意味着图像以中等尺寸显示。我实现了这样的代码。

 images = [[NSMutableArray alloc]init];
[images addObject:[UIImage imageNamed:@"bearlarge.jpg"]];
[images addObject:[UIImage imageNamed:@"bufflo_large.jpg"]];
[images addObject:[UIImage imageNamed:@"camel_large.jpg"]];
UIView *view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];



int row = 0;
int column = 0;


for(int i = 0; i < images.count; ++i) {



// UIImage *thumb = [images objectAtIndex:i];

UIButton * button = [UIButton buttonWithType:UIButtonTypeRoundedRect];



button.frame = CGRectMake(column*105+14, row*105+10, 50,50);


[button setImage:[images objectAtIndex:i] forState:UIControlStateNormal];
[button addTarget:self
action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
button.tag = i;




[view addSubview:button];

if (column == 2) {
column = 0;
row++;
} else {
column++;
}
}
//[view setContentSize:CGSizeMake(320, (row+1) * 80 + 10)];
self.view = view;
[view release];

任何人都可以向我发送有关如何调整 iPhone 中按钮图像大小的代码吗?

提前谢谢您。

最佳答案

您可以为 UIImage 创建此类别:

- (UIImage *)rescaleImageToSize:(CGSize)size {
CGRect rect = CGRectMake(0.0, 0.0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
[self drawInRect:rect]; // scales image to rect
UIImage *resImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resImage;
}

关于iphone - 如何调整 iPhone 中按钮图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4601445/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com