0

スクロールビューにいくつかのボタンを追加しています。ボタンの背景を画像で設定しています。出力を見ると、画像が引き伸ばされているように見えます。これは避けたいと思います。

だから私はこれを試しました:

画像を処理するカスタム ビューを作成し、この画像を端から固定しました。

自動サイズ変更部分に対してこれを行いました:

ここに画像の説明を入力

私のコードは次のようになります。

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];
}

ボタンに追加したときに画像が伸びないようにする方法についてのガイダンスが必要です。

他の提案も歓迎します..

4

1 に答える 1

0

それはおそらく画像ビューの問題contentModeです。

于 2013-04-03T03:09:02.993 に答える