2012-01-31 2 views
0

私はいくつかのWWDCビデオを見ていて、UIImageViewを使って余分なメモリを必要としないように画像を伸ばしました。それらの例では、音楽アプリでtableViewCellを長押ししたときのように、小さなテキストバブルを使用していました。次に、中央の部分には、長い押していたtableViewCellを指す下の小さな三角形があるので、3つのスライス、左、右、中央に分割する必要がある方法について説明します。彼らの例でコードを提供していないので、誰かがこれをどのようにして行うのかを説明することができますか?疑似コードは問題ありません。ドキュメントを見ると、私の推測がある:UIImageView autoresizingmask、UIImage stretchableImageWithLeftCapWidth

は、あなたのグラフィックエディタから最小サイズの3 UIImages作成:

UIImage *leftImage = [UIImage imageNamed:@"left.png"]; 
UIImage *rightImage = [UIImage imageNamed:@"right.png"]; 
UIImage *centerImage = [UIImage imageNamed:@"center.png"]; 

leftImage = [leftImage stretchableImageWithLeftCapWidth:0 topCapHeight:0]; 
rightImage = [rightImage stretchableImageWithLeftCapWidth:0 topCapHeight:0]; 
centerImage = [centerImage stretchableImageWithLeftCapWidth:0 topCapHeight:0]; 

UIImageView *leftImgView = [[UIImageView alloc] initWithImage:leftImage]; 
leftImgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

UIImageView *rightImgView = [[UIImageView alloc] initWithImage:rightImage]; 
leftImgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

UIImageView *centerImgView = [[UIImageView alloc] initWithImage:centerImage]; 
leftImgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 

// do I just add them all to the subview of self.view? Do I need to set their frames somewhere? If so, how do I know where they go since it's 3 slices making up an image. 
// release memory 

をあなたはIBでこれをどのように行う場合は、このトピックに私の関連質問です。 3つのimageViewsを画面全体に表示させるように、イメージを展開するのが好きですか?

答えて

2

実際には、3つの画像を作成する必要はありません。伸縮可能なUIImageのポイントは、それが中間を伸ばしているが、ユーザが定義できる終わりではないということです。横と縦の領域は、伸ばしたくないピクセル単位で定義します。

UIImage *stretchyImage = [image stretchableImageWithLeftCapWidth:12.0 topCapHeight:0.0] 

は、それからちょうどあなたが希望のサイズに設定します。

使用が本当に簡単であるが、ここでは一例です。イラスト付きのいいドキュメントは​​です。

EDIT: 伸縮可能なイメージをプログラムで作成する必要があると思います。hereを参照してください。

関連する問題