I'm trying to get the CGPoint from the center property of some UILabels (which is part of an outlet collection). Now, when i do:
for (UILabel *label in labelCollection) {
NSLog(#"%f", label.center.x);
}
It simply returns 0, same with the center.y? how come? i need those coordinates hehe :)
thanks on advance
//EDIT
Uploaded a picture: the labels with "a" "b" "c" "d" is the labels i'm talking about. i tried changing the text.property in the code and that works well, but it just wont give me the coordinates it's on.
Verify that the view has a superview. The value depends on the superview's coordinates.
I figured out the answer, it had to do with the fact that i was doing the whole thing in viewDidLoad, and i should be doing it in viewDidAppear. it must be because on viewDidLoad, it hasn't been placed yet, and therefore i could still change the text, coz the object label was created, but i couldnt get the origin coz it was not placed yet.
thanks for helping lads.
You remove the constraints then run the app may be constraint create the problem because new xcode constraints create problem on some functions and properties so first remove the constraints by uncheck the "Use autlayout "then you check the app
Related
I have been trying to insert a UIButton programatically, as I am using Autolayout I have done something like that...
[self.add_scroll_view addConstraints : [NSLayoutConstraint constraintsWithVisualFormat : #"V:[date_picker_btn]-[button(==date_picker_btn)]"
options:0
metrics:nil
views:NSDictionaryOfVariableBindings(date_picker_btn, button)]];
I have two questions here...
i) Button inserted is not the same width as date_picker_btn even though I mentioned button(==date_picker_btn).
ii) I have inserted properely, however below views should align accordingly down to accommodate new button... How to do that...
Thanx
When using the visual format language, the superview of the view for which the constraint is being described is represented by the | character.
Example:
V:|-20-[mybutton1(>=70#500)]-[mybutton2(==mybutton1)]-30-[mybutton3]-|
Refer this link
For first question I have mentioned V: so it means (==) will assign height not width. To set width it should start with H:.
Next question, To insert a button between two existing button need to handle already existing constraints, here above I have added new constraints only not handle old existing, so I have to delete the existing constraints, so that it avoid conflicts. Works fine.. Happy coding :)
I have a scence with a bunch of labels and buttons. When you tap on a button a view slides up from the bottom with controls in it, a kind of keyboard so to say. It "looks" like this:
-----------------------------
| |
| [Button 1] [ Slider 1 ] |
| |
| [Button 2] [ Slider 2 ] |
| |
-----------------------------
This "keyboard" is created at the very beginning when the view loads and the animation is done switching its heigth from 0 to its instrinsic content size. This escene only supports landscape mode and it took me quite a while to keep the "keyboard" on the view when the device rotates 180 degrees.
The problem I see pops up with either of the two following situations:
The device rotates 180 degrees.
The "keyboard" is called.
This problem as follows:
Unable to simultaneously satisfy constraints...
.
.
.
.
(
"<NSLayoutConstraint:0x718c6c0 UIButton:0x717e0d0.centerY == UISlider:0x717d9d0.centerY>",
"<NSLayoutConstraint:0x7190a00 UIButton:0x717e0d0.centerY == UISlider:0x717d9d0.centerY>"
)
The error log gives me this error twice, once for each set of button-slider.
What I think is weird is that the conflicting constraints are exactly the same. I thought I did some copy-paste mistake and added the same constraint twice, but it's not the case.
I'm guessing it has something to do with updateViewConstraints being called upon rotation and also whe I perform the animation, but I cannot see why only these constraints are affected since there are some more in this "keyboard" view.
All and all, this Autolayout is beign quite more difficult than Apples whants to claim. In my opinion, of course.
Any ideas?
EDIT: the constrains are set all in code using mainly the visual language format. The constrains of the controls inside the "keyboard" are added into the "keyboard" view which is the normal thing to do, I believe.
Just to try it out, I changed the problematic constraints and, instead to adding them to the "keyboard" subview, I added them to the self.view ("keyboard" superview). All the sudden, no more errors are shown.
Despite of that, I'd really like some discussion on the matter because I still don't know what's wrong and I just had a lucky shot. I'd really like to undestand it.
The fact that the conflicting constraints are exactly the same is in fact the error. With Auto Layout, you can't have a constraint twice. That will generate the error you see above.
Definitely, you have added the constraint twice. You can see this from the memory addresses. You have two different NSLayoutConstraint instances, 0x718c6c0 and 0x7190a00. However, the instances each refers to are both the same. That being that the vertical center centerY of your UIButton instance 0x717e0d0 should be in the middle of the UISlider 0x717d9d0.
Possibly your updateConstraints method has been called and you haven't checked to see if a constraint already exists before adding it again.
I don't know if this may help you but I just used this tutorial for setting up constraints to buttons and labels in my app
I was just experimenting with layer property of my UIButton by setting a outlet n the code for a button created in xib.
NSLog(#"d button layer value%#",dButton.layer.backgroundColor);
But the output is coming as:
d button layer value(null)
My question is: can't we display the layer property value of UIButton. We all know that some default value would have been set for the button.
According to the documentation for CALayer:
The default is nil.
unless you explicitly change it.
In the documentation for UIView, it says this:
The default value is nil, which results in a transparent background color.
This excerpt describes the view.backgroundColor property, so I assume that the view.layer.backgroundColor property is the same.
Hope this helps!
Phew !! I finally got the answer.
Actually I was trying to display the structure value using %# in NSlog statement.
dButton.layer.backgroundColor is a fundamental data type used internally by Quartz to represent colors.
So, way to display them is to make your own class which can parse the value.
Like, for example there are class functions for CGRect, CGPoint etc
like for displaying CGRect we use this code
NSLog(#"d button layer value%#",NSStringFromCGRect(dButton.layer.bounds));
but there arent any function defined for CGColorRef.
Ok, as per jrturton said,for displaying the above value we can use
NSLog(#"d button layer value%#",[UIColor colorWithCGColor:button.layer.backgroundColor)]
I hope everyone got it now !!
In my iPhone app I want to have a UIPickerView with 2 components. Initially the left column will be wide and the right column narrow to enable the text on the left to be read easily to allow selection from it.
Once this column has been selected the user will click on the right column to select an item from it : when this happens I want to resize the columns so that the left column is narrow and the right one is wide so that all the text can be read.
I have been experimenting with "pickerView widthForComponent" but this seems to only get called when the view is initially loaded.
Is there any way I can dynamically resize the columns ?
Thanks
You may use [pickerView reloadAllComponents].
Update:
That's weird. You may also try to check the following solution.
Just a reload won't work. You also need to call setNeedsLayout
[pickerView reloadAllComponents];
[pickerView setNeedsLayout];
On view in IB I have numerous items (including view itself). ONLY one item has tag 0, yet following line works for ANY UITextBox other then the one with tag 0. Note that only ONE UITextBox has tag 0, why:
(UITextField *) [self.view viewWithTag:0]).text = #"foo";
Interesting that when triggered event received for the element with tag 0, I can get value of Tag 0 with no problem.
Is there a limitation to look for tag 0 elements?
All views have a 0 tag as a default so if you get a 0 view it could be any view. For it to work you need to use non-zero values that you set in your program or within Interface builder.
actually, if you ask a view called "X" for a viewwithtag 'zero', you will probably get the "X" view as the return value :/ idiotic behaviour. send regards to apple
que is right. I just got bit by this.
From the docs:
Discussion This method searches the current view and all of its
subviews for the specified view.
At least it's documented correctly. I guess we need a method called "subviewWithTag:"
set self tag as -1. won't affect other view's tag.