0

現在 UAModalPanel を使用していますが、このコンポーネントで写真を表示したいだけです。だから私は次のことをしました:

#import <UIKit/UIKit.h>
#import "UAModalPanel.h"

@interface LolcatPanel : UAModalPanel

- (void)showLolcat;

@end


#import "LolcatPanel.h"

@implementation LolcatPanel

- (void)showLolcat
{
    int pic = (arc4random() % 10) + 1;
    NSString *intString = [NSString stringWithFormat:@"%d", pic];
    NSMutableString *picture = [[NSMutableString alloc] initWithString:intString];
    [picture appendString:@".jpg"];
    NSLog(@"Loading image %@", picture);

    NSString* imageName = [[NSBundle mainBundle] pathForResource:intString ofType:@"jpg"];

    UIImage *testImage = [UIImage imageWithContentsOfFile:imageName];

    if (testImage == nil) {
        NSLog(@"FAILED");
    }

    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
    imgView.image = testImage;
    imgView.contentMode = UIViewContentModeScaleToFill;

    [self addSubview:imgView];
}

@end

UAModelPanel に収まる画像を表示したいのですが、ATM の結果はあまり良くありません。

4

2 に答える 2

0

画像ビューが表示されたときのサイズを確認します。また、変更されたスーパービューに対する既知の反応があるように、自動サイズ変更/自動レイアウトを構成する必要があります。

見栄えを良くするために、スケール フィル コンテンツ モードの代わりにアスペクト フィットに切り替えることをお勧めします。clipToBounds設定された境界外に画像が描画されないように、画像ビューを に設定する必要がある場合もあります。

于 2013-08-22T15:03:41.693 に答える
0

私は解決策を見つけました:

UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(22, 20, width, height)];
imgView.image = testImage;
imgView.contentMode = UIViewContentModeScaleAspectFit;

[self.contentContainer addSubview:imgView];

imageview を contentcontainer に追加する必要がありました。

よろしく、サシャ

于 2013-08-22T15:12:55.747 に答える