Here, I have pointed to the Referencing Outlet Collection
. I am not able to figure out its usage in XCode4.
在这里,我已经指出了引用的Outlet集合。我不能算出它在XCode4中的用法。
I am asking for the `new feature of REFERENCING OUTLET COLLECTION in InterfaceBuilder of XCode4".
我要求的是“在XCode4的InterfaceBuilder中引用OUTLET COLLECTION的新特性”。
4 个解决方案
#1
55
The IBOutletCollection
is a way to group IBOutlets
. Imagine that you have 3 or 4 UILabels
, on which you will apply a style (font, backgroundColour, opacity, etc). With a IBOutletCollection
, it becomes trivial to do this. First you need to define your IBOutletCollection
:
IBOutletCollection是一种组织iboutlet的方法。假设您有3或4个UILabels,您将在其中应用一个样式(字体、背景颜色、不透明度等)。有了IBOutletCollection,这样做就变得很简单了。首先需要定义IBOutletCollection:
@property (nonatomic, retain) IBOutletCollection(UILabel) NSArray *labelsCollection;
(notice the type we are putting inside parenthesis, although we could put an id
, if we had a mix collection)
(注意我们放入括号内的类型,尽管我们可以添加id,如果我们有一个混合集合)
Connect the IBoutlets
on Interface Builder and then just iterate it:
在接口构建器上连接iboutlet,然后迭代它:
for(UILabel *label in labelsCollection)
{
// Apply your styles
}
Hope this helps you understand:
希望这能帮助你理解:
http://useyourloaf.com/blog/2011/3/28/interface-builder-outlet-collections.html
http://useyourloaf.com/blog/2011/3/28/interface-builder-outlet-collections.html
#2
0
Ive just been hacking XIBs.
我刚刚被黑客攻击了。
You can see a Outlet collection in use here:
您可以在这里看到一个Outlet collection:
A control can have multiple gesture recognizers which are stored in :
控件可以有多个手势识别器,它们存储在:
UITouch
@property(nonatomic,readonly,copy) NSArray *gestureRecognizers
Open IB
开放的IB
Drag UITextView to a IB View.
将UITextView拖到IB视图。
Drag Pinch Gesture Recognizer to the textview.
将手势识别器拖拽到textview。
Click on each in the tree of objects and open the Connections Inspector.
单击对象树中的每一个,打开连接检查器。
you'll see its been added a collection, not a single outlet.
您将看到它被添加了一个集合,而不是一个outlet。
OUTLET COLLECTIONS
gestureRecognizers ------> Pinch Gesture
#3
0
Using XCode Interface Builder create/connect your IBOutlets to the IBOutlet Collection. As result, you will get the following code in .h file:
使用XCode接口构建器创建/连接您的IBOutlet到IBOutlet集合。因此,您将在.h文件中得到以下代码:
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *labels;
In the .m file you can iterate using for-loop to get your desired features like font size or color:
在.m文件中,您可以循环使用for循环来获得所需的特性,如字体大小或颜色:
for (UILabel *label in self.labels) {
label.font = [UIFont systemFontOfSize:14];
label.textColor=[UIColor blueColor];
}
or
或
@synthesize labels;
...
for (UILabel *label in labels) {
label.font = [UIFont systemFontOfSize:14];
label.textColor=[UIColor blueColor];
}
#4
-1
swift:
// create outlet colllections
@IBOutlet var name: [UILabel]!
@IBOutlet var ageLabel: [UILabel]!
@IBOutlet var genderLabel: [UILabel]!
@IBOutlet var weightLabel: [UILabel]!
@IBOutlet var heightLabel: [UILabel]!
@IBOutlet var bmiLabel: [UILabel]!
@IBOutlet var smokerLabel: [UILabel]!
@IBOutlet var hdraLabel: [UILabel]!
// declare global vars
var names: UILabel;
var ageLabels: UILabel;
var genderLabels: UILabel;
var weightLabels: UILabel;
var heightLabels: UILabel;
var bmiLabels: UILabel;
var smokerLabels: UILabel;
var hdraLabels: UILabel;
// assign values
for name:UILabel in self.name {
self.names = name
}
for ageLabel:UILabel in self.ageLabel {
self.ageLabels = ageLabel
}
for genderLabel:UILabel in self.genderLabel {
self.genderLabels = genderLabel
}
for weightLabel:UILabel in self.weightLabel {
self.weightLabels = weightLabel
}
for heightLabel:UILabel in self.heightLabel {
self.heightLabels = heightLabel
}
for bmiLabel:UILabel in self.bmiLabel {
self.bmiLabels = bmiLabel
}
for smokerLabel:UILabel in self.smokerLabel {
self.smokerLabels = smokerLabel
}
for hdraLabel:UILabel in self.hdraLabel {
self.hdraLabels = hdraLabel
}
#1
55
The IBOutletCollection
is a way to group IBOutlets
. Imagine that you have 3 or 4 UILabels
, on which you will apply a style (font, backgroundColour, opacity, etc). With a IBOutletCollection
, it becomes trivial to do this. First you need to define your IBOutletCollection
:
IBOutletCollection是一种组织iboutlet的方法。假设您有3或4个UILabels,您将在其中应用一个样式(字体、背景颜色、不透明度等)。有了IBOutletCollection,这样做就变得很简单了。首先需要定义IBOutletCollection:
@property (nonatomic, retain) IBOutletCollection(UILabel) NSArray *labelsCollection;
(notice the type we are putting inside parenthesis, although we could put an id
, if we had a mix collection)
(注意我们放入括号内的类型,尽管我们可以添加id,如果我们有一个混合集合)
Connect the IBoutlets
on Interface Builder and then just iterate it:
在接口构建器上连接iboutlet,然后迭代它:
for(UILabel *label in labelsCollection)
{
// Apply your styles
}
Hope this helps you understand:
希望这能帮助你理解:
http://useyourloaf.com/blog/2011/3/28/interface-builder-outlet-collections.html
http://useyourloaf.com/blog/2011/3/28/interface-builder-outlet-collections.html
#2
0
Ive just been hacking XIBs.
我刚刚被黑客攻击了。
You can see a Outlet collection in use here:
您可以在这里看到一个Outlet collection:
A control can have multiple gesture recognizers which are stored in :
控件可以有多个手势识别器,它们存储在:
UITouch
@property(nonatomic,readonly,copy) NSArray *gestureRecognizers
Open IB
开放的IB
Drag UITextView to a IB View.
将UITextView拖到IB视图。
Drag Pinch Gesture Recognizer to the textview.
将手势识别器拖拽到textview。
Click on each in the tree of objects and open the Connections Inspector.
单击对象树中的每一个,打开连接检查器。
you'll see its been added a collection, not a single outlet.
您将看到它被添加了一个集合,而不是一个outlet。
OUTLET COLLECTIONS
gestureRecognizers ------> Pinch Gesture
#3
0
Using XCode Interface Builder create/connect your IBOutlets to the IBOutlet Collection. As result, you will get the following code in .h file:
使用XCode接口构建器创建/连接您的IBOutlet到IBOutlet集合。因此,您将在.h文件中得到以下代码:
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *labels;
In the .m file you can iterate using for-loop to get your desired features like font size or color:
在.m文件中,您可以循环使用for循环来获得所需的特性,如字体大小或颜色:
for (UILabel *label in self.labels) {
label.font = [UIFont systemFontOfSize:14];
label.textColor=[UIColor blueColor];
}
or
或
@synthesize labels;
...
for (UILabel *label in labels) {
label.font = [UIFont systemFontOfSize:14];
label.textColor=[UIColor blueColor];
}
#4
-1
swift:
// create outlet colllections
@IBOutlet var name: [UILabel]!
@IBOutlet var ageLabel: [UILabel]!
@IBOutlet var genderLabel: [UILabel]!
@IBOutlet var weightLabel: [UILabel]!
@IBOutlet var heightLabel: [UILabel]!
@IBOutlet var bmiLabel: [UILabel]!
@IBOutlet var smokerLabel: [UILabel]!
@IBOutlet var hdraLabel: [UILabel]!
// declare global vars
var names: UILabel;
var ageLabels: UILabel;
var genderLabels: UILabel;
var weightLabels: UILabel;
var heightLabels: UILabel;
var bmiLabels: UILabel;
var smokerLabels: UILabel;
var hdraLabels: UILabel;
// assign values
for name:UILabel in self.name {
self.names = name
}
for ageLabel:UILabel in self.ageLabel {
self.ageLabels = ageLabel
}
for genderLabel:UILabel in self.genderLabel {
self.genderLabels = genderLabel
}
for weightLabel:UILabel in self.weightLabel {
self.weightLabels = weightLabel
}
for heightLabel:UILabel in self.heightLabel {
self.heightLabels = heightLabel
}
for bmiLabel:UILabel in self.bmiLabel {
self.bmiLabels = bmiLabel
}
for smokerLabel:UILabel in self.smokerLabel {
self.smokerLabels = smokerLabel
}
for hdraLabel:UILabel in self.hdraLabel {
self.hdraLabels = hdraLabel
}