我正在看一些WWDC視頻,他們談論使用UIImageView來拉伸你的圖像,不會產生任何額外的內存。他們的例子是使用一個小文本泡泡,就像您在Music應用程序中長按tableViewCell時所獲得的泡泡一樣。然後他們會談論如何將它分成3片,左邊,右邊和中間,因爲中間部分底部有一個小三角形,指向您長時間按下的tableViewCell。有人可以解釋某人如何做這件事,因爲他們沒有在他們的例子中提供任何代碼?僞代碼很好。綜觀文檔,我的猜測是:UIImageView autoresizingmask,UIImage stretchableImageWithLeftCapWidth
從圖形編輯器創建的最小尺寸三個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佔據整個屏幕,因爲這是你想要的圖像擴大到?