2012-05-02 89 views
1

我想知道從以下佈局實現的最佳方式/正確方法?我想在UITableView的UITableViewCell之外放置一個具有靜態單元的UIImageView。更改UITableViewCell寬度以適合單元格外的UIImageView

Screenshot of what i'm trying to achieve

我已通過使用以下代碼

- (void)setFrame:(CGRect)frame { 
    frame.size.width -= 125.0; 
    [super setFrame:frame]; 
} 

在的UITableViewController的viewDidLoad在第1子類的UITableViewCell的細胞做了以下我添加它根據所述的UIImageView和位置自定義UITableViewCell的寬度。

這類作品,但我不知道如何處理旋轉,以及如果我迄今爲止所做的將是正確的方式?

回答

0

我設法產生我想要的使用後續,這是探索性的不是最好的方式或最乾淨的方式,但由於沒有人從StackOverFlow給出了更好的建議,我想我更好地回答這個問題。

我分類了前3個UITableViewCells並設置了幀大小以考慮到我的圖像的大小。

- (void)setFrame:(CGRect)frame { 
float cellWidth = (frame.size.width - 345); 
frame.size.width = cellWidth; 

[super setFrame:frame]; 

}在我的UITableViewController的viewDidLoad創建

然後使用第一靜態細胞在tableview中作爲一個IBOutlet( 「firstCell」)定位的UIImageView。然後我設置了autoResizingMask,它將旋轉排序並最終將UIImageView添加到視圖中。

//Create and position the image view 
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((firstCell.frame.size.width), (firstCell.frame.origin.y + 70), 300, 137)]; 

// Add border and round corners of image view to make style look a little like tableviewcells 
[imageView.layer setBorderColor:[UIColor colorWithWhite:0 alpha:0.5].CGColor]; 
[imageView.layer setBorderWidth:2.0]; 
[imageView.layer setCornerRadius:5.0]; 
[imageView setClipsToBounds:YES]; 

//Set the image in the image view 
UIImage *image = [UIImage imageNamed:@"defaultPicture.png"]; 
imageView.image = image; 

//Set resizing of image view for when view is rotated 
imageView.contentMode = UIViewContentModeRedraw; 
imageView.autoresizingMask = UIViewContentModeScaleAspectFit; 

//Add tap gesture for imageview to initiate taking picture. 
imageView.userInteractionEnabled = YES; 
UITapGestureRecognizer *imageViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(takePicture:)]; 
[imageView addGestureRecognizer:imageViewTap]; 

//Add image view to view 
[self.view addSubview:imageView]; 

landscape portrait

這還沒有經過全面檢測,我敢肯定,是不是一個偉大的實現,但其之後我是效果的起點。如果您知道更好的方法,請回復。

注:上面的代碼爲我的iPad上的截圖,但寫的應用程序從測試我在iPhone上做

0

有不同的方法來做到這一點。一種方法是設置表格視圖的寬度較小,如圖2所示,使用自定義表格視圖單元格和所需的單元格添加圖像,以便顯示單元格數據和圖像。我認爲自定義單元會是更好的解決方案。告訴我,如果你問我同樣的事情我回答,如果不是,那麼我檢查我的答案謝謝。

+0

我不想改變UITableView的寬度,因爲這會影響在第二部分中的其他行。我想使用自定義單元格方法,但想知道實現此方法的正確方法。 –

+0

@MattPrice所以你想要如何實現自定義單元格。 – vishiphone

+0

@vishiphone看看我的答案在下面。我做了我想要的。我不能將它標記爲10小時回答 –

相關問題