如果您希望它是一个简单的视图,那么您可以创建一个带有几个 UITextField 的 UIView 子类,并且可能创建一个或两个 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";
// ...
您可以在 Interface Builder 中创建视图中的实际 UI 元素,也可以在代码中创建。做什么是一种个人喜好。两者都有优点和缺点,在这种情况下,在代码中构建视图将非常容易,并且不需要您拥有两个文件即可使用控件。