我可以將UiLabel programaticaly添加到UiScrollWiev,因爲我已閱讀 http://developer.apple.com/library/ios/#documentation/uikit/reference/UILabel_Class/Reference/UILabel.html 而我沒有找到任何構造函數。 有沒有辦法做到這一點?Objective C如何將UiLabel添加到UiScrollWiev
1
A
回答
1
[myScrollView addSubview:myLabel];
[myLabel release];
添加視圖發生在父容器視圖中,而不是正在添加的視圖。
而且一旦它加入到上海華時,上海華擁有它,你應該釋放它。
編輯:OP問,「但是當我創建它們的10是它們放置在彼此會發生什麼?」
編號每個UIView子類(UIScrollView和UILabel都有)具有.frame
屬性,其中包含一個CGRect結構。該字段定義了對象的位置和大小。
所以:
UILabel *one = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
UILabel *two = [[UILabel alloc] initWithFrame:CGRectMake(0, 35, 200, 30)];
UILabel *three = [[UILabel alloc] initWithFrame:CGRectMake(0, 70, 200, 30)];
[myScrollView addSubview:one];
[myScrollView addSubview:two];
[myScrollView addSubview:three];
[one release];
[two release];
[three release];
那會放三個UILabels,他們每個人200像素寬由30像素高的滾動視圖,所有的人都反對這種觀點的左側平齊,頂部一個正確,一個35 px下跌,一個70 px下跌。
如果UIScrollView的內容大於UIScrollView的.frame
,那麼設置一個.contentSize
屬性(同樣是CGRect),該屬性定義了要滾動的內容的區域。
相關問題
- 1. 添加UILabel查看objective-c
- 2. 如何將字符添加到iOS中使用Objective-C動畫的UILabel?
- 3. 如何將反射添加到UILabel。 IOS
- 4. 如何將UILabel添加到UIAlertController中
- 5. 將C++對象添加到Objective-C類
- 6. 將UILabel添加到圖像
- 7. 將按鈕添加到UILabel
- 8. 將UILabel添加到UIImageView
- 9. Circular UILabel Objective C
- 10. objective-C++如何將方法添加到C++類
- 11. 將SearchBar添加到NavigationBar Objective-C iOS 9
- 12. Objective C如何將文本字段添加到導航欄中
- 13. Objective C - 如何將方法添加到現有類中?
- 14. 如何在Objective-C中將屬性添加到NSObject?
- 15. Objective-C iOS如何將UIPageControl添加到我的CollectionView?
- 16. 如何將圖像添加到ios objective c中的uiactivityindicator視圖?
- 17. 如何將UIImage添加到Objective-C中的MSMutableArray?
- 18. 如何將對象添加到Objective-C中的數組?
- 19. 如何在iOS中掩蓋UILabel - Objective-C
- 20. IOS/Objective-C:延遲加載UILabel
- 21. 如何添加UILabel上面的UILabel
- 22. 如何添加填充到UILabel?
- 23. 將UILabel添加到UITableViewCell的detailTextLabel
- 24. 將背景圖像添加到UILabel
- 25. 將CALayer添加到UILabel文本
- 26. Objective-C命名UILabel iOS
- 27. 如何將加號按鈕添加到objective-c中表格視圖的右側?
- 28. 將過程標籤添加到Objective-C和C代碼
- 29. 如何將UIVibrancyEffect添加到現有的UILabel(IBOutlet)?
- 30. 如何將文本添加到UILabel背景圖像
非常感謝快速answer.But當我創建它們中的10個,他們劃歸對方,會發生什麼? – Csabi 2011-01-13 13:10:04