[英]UIImageView autoresizingmask, UIImage stretchableImageWithLeftCapWidth
我正在觀看一些WWDC視頻,他們談論使用UIImageView來拉伸你的圖像,不會產生任何額外的記憶。 他們的例子是使用一個小文本泡泡,就像你在音樂應用程序中長按tableViewCell時得到的那個。 然后他們討論如何將它分成3個切片,左,右和中心,因為中心部分底部有一個小三角形,指向你長按的tableViewCell。 有人可以解釋某人是如何做到的,因為他們沒有在他們的例子中提供任何代碼嗎? 偽代碼很好。 看一下文檔,我的猜測是:
從圖形編輯器創建三個最小尺寸的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占據整個屏幕一樣,因為那是你想要的圖像擴展到什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.