スクロールビューにいくつかのボタンを追加しています。ボタンの背景を画像で設定しています。出力を見ると、画像が引き伸ばされているように見えます。これは避けたいと思います。
だから私はこれを試しました:
画像を処理するカスタム ビューを作成し、この画像を端から固定しました。
自動サイズ変更部分に対してこれを行いました:
私のコードは次のようになります。
for (int counter = 0; counter < imageCount; counter++) {
NSString *imageName = [NSString stringWithFormat:@"%@_img0%d.jpg",mRoutePointId,counter+1];
UIImage *infoImage = [UIImage imageNamed:imageName];
GalleryImage *galleryItem = [[GalleryImage alloc] initWithImage:infoImage];
UIButton *infoImageButton = [[UIButton alloc] initWithFrame:CGRectMake(xOffset, 0, infoImagesScrollView.frame.size.width, infoImagesScrollView.frame.size.height)];
infoImageButton.tag = counter;
[infoImageButton setImage:galleryItem.galleryImage forState:UIControlStateNormal];
[infoImageButton setImage:galleryItem.galleryImage forState:UIControlStateHighlighted];
[infoImageButton addTarget:self action:@selector(infoImageButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
[infoImageButton setTitle:[NSString stringWithFormat:@"%@_img0%d.jpg",mRoutePointId,counter+1] forState:UIControlStateApplication];
[infoImagesScrollView addSubview:infoImageButton];
xOffset+=infoImagesScrollView.frame.size.width;
}
CustomView.m
#import "GalleryImage.h"
@implementation GalleryImage
@synthesize galleryImage;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (id)initWithImage:(UIImage*) image
{
self = [super init];
if (self) {
// galleryImageView = nil;
galleryImage = image;
}
return self;
}
-(void)awakeFromNib
{
[galleryImageView setImage:galleryImage];
}
ボタンに追加したときに画像が伸びないようにする方法についてのガイダンスが必要です。
他の提案も歓迎します..