わっふるわっふる
この広告は、90日以上更新していないブログに表示しています。
iphone
cocoa
デフォルトだと
UIImageView に UIImage を貼付けると、どんな縦横比の画像だろうと問答無用で
UIImageView のサイズに変換されて貼付けられてしまう。
contentMode を設定する
UIImageView の contentMode プロパティに UIViewContentModeScaleAspectFit をセットすることで
画像の縦横比を維持したまま UIImageView に貼付けることが可能となる。
また、contentMode に貼付けることができるのは以下
typedef enum {
UIViewContentModeScaleToFill, // これがデフォルト。UIImageViewにめいっぱいひろげる
UIViewContentModeScaleAspectFit, // 画像のaspect比を維持し、ちょうどはいるようにする
UIViewContentModeScaleAspectFill, // 画像のaspect比を維持し、めいっぱい広げる(はみ出した分がみれなくなる)
UIViewContentModeRedraw, // UIViewContentModeScaleToFill これと同じに見えるけどなんだろう・・
UIViewContentModeCenter, // 画像サイズをそのままに、真ん中を表示
UIViewContentModeTop, // 上を
UIViewContentModeBottom, // 下を
UIViewContentModeLeft, // 左を
UIViewContentModeRight, // 右を
UIViewContentModeTopLeft, // 左上を
UIViewContentModeTopRight, // 右上を
UIViewContentModeBottomLeft, // 左下を
UIViewContentModeBottomRight, // 右下を
} UIViewContentMode;
サンプル
#import <UIKit/UIKit.h>
@interface RnamikiViewController : UIViewController
@end
@implementation RnamikiViewController
- (void)loadView {
UIImageView *imageView = [[UIImageView alloc]init];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.image = image;
[image release];
self.view = imageVew;
[imageView release];
}
@end
rnamiki
広告を非表示にする
プロフィール
id:rnamiki
読者です
読者をやめる
読者になる
読者になる
このブログについて
検索
リンク
●
はてなブログ
●
ブログをはじめる
●
週刊はてなブログ
●
はてなブログPro
最新記事
C++ で libcurl と libxml2 使ってみる
アプリ﹁.folder﹂をリリースしました!
アプリでグルグル画像(indicator)をIBを使わずに簡単に表示させる方法
IDPへの参加と実機で動かせるようにするまで
画像サイズにあわせてUIImageViewに貼付ける
月別アーカイブ
▼
▶
2009
●
2009 / 8
●
2009 / 6
●
2009 / 3
●
2009 / 2
▼
▶
2008
●
2008 / 12
●
2008 / 10
●
2008 / 4
●
2008 / 3
●
2008 / 2
▼
▶
2007
●
2007 / 10
●
2007 / 8
はてなブログをはじめよう!
rnamikiさんは、はてなブログを使っています。あなたもはてなブログをはじめてみませんか?
はてなブログをはじめる︵無料︶
はてなブログとは
Powered by Hatena Blog
|
ブログを報告する
引用をストックできませんでした。再度お試しください