如果你希望它是一個簡單的觀點,那麼你可以創建一個UIView子類的幾個UITextFields的,可能一個的UIImageView或兩個都有網點,使您的控制器能夠進行更改。例如:
@interface StockInfo <UIView>
@property (nonatomic, strong, readonly) UITextField *ticker;
// You may want to make these numbers so that you can do calculations with them, and then update the text field automatically
@property (nonatomic, strong, readonly) UITextField *price;
@property (nonatomic, strong, readonly) UITextField *priceChange;
// This could be automatically calculated based on the price and priceChange if appropriate
// It could also automatically show the Up or Down indicator
@property (nonatomic, strong, readonly) UITextField *percentChange;
@end
然後,控制器可以創建一個實例,並設置各種屬性:
StockInfo *djia = [[StockInfo alloc] init];
djia.ticker = @"DJIA";
djia.price = @"14550.35" ;
djia.priceChange = @"-111.66";
// ...
您可以創建視圖界面生成器內或者在實際的UI元素,或做在碼。該做什麼是一種個人喜好。在這種情況下,有兩個方面的優缺點,並且在這種情況下構建代碼視圖會非常容易,並且不要求您有兩個文件才能使用該控件。
閱讀本書後,我對IB的印象是,它用於創建整個應用程序窗口的佈局。我不確定我是否可以使用它來創建可重用的UI組件。 – prashant 2013-04-03 20:41:42
這就是你幸運的地方! :) IB可用於構建UITableViewCells,custon子視圖中的圖像視圖,視圖上的自定義手勢以及更多全部內容。所有你需要做的是選擇正確的類從子類!坦率地說,當我需要快速定製一些東西,同時保持設計整潔時,它對我來說變成了一個寶貴的工具! :) – wayway 2013-04-03 20:43:38
@prashant,不,您可以使用* Interface Builder *(現在是Xcode的一部分)來創建小的可重用視圖。在Inspector屬性中,只需將大小設置爲'freeform',然後指定所需的點大小(寬度和高度)即可。然後,你會有一些不是全屏的東西。 – Nate 2013-04-03 20:44:36