Why cant I display the layer property value of Uibutton - iphone

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 !!

Related

NSTableView with custom cell view and NSArrayController bindings drawing a blank string

It took me forever to figure out how to set up editing on a custom cell view for an NSTableView. Thanks to StackOverflow I figured that much out. P.S. I was doing all of this in Interface Builder.
I have a single column table in which the cell is a custom multi-control NSTableCellView, with:
name (in bold)
description
detail
It's all text. Set up editability on the name only. The table is sorted by the name.
When I edit the name, it has the effect on the bound model that I expect. The table even re-sorts correctly. However, it's displaying incorrectly. The description and detail (not editable) still show up correctly, but the name (which was edited) is a blank. When I inspect the model, it has the correct updated value. But the cell view itself is incorrect.
This doesn't happen all the time--it typically happens if the cell is re-sorted to the top or bottom of the table, but that may be a red herring and may instead have to do with NSTableView cell caching or something.
I hacked up a workaround in which I assign a delegate to the NSTextField (automatically generated for the NSTableCellView) and intercept the textShouldEndEditing event. For some reason this event is getting triggered twice for a given edit (after I press "enter" in the text field)--once for the actual edit where fieldEditor.string is different from the model name, followed by another event where fieldEditor.string is the same as the model name. If I return false for my textShouldEndEditing handler in the latter case, then the cell contents end up being drawn correctly. That's the hack.
I feel like I'm doing something wrong here though, and that shouldn't be necessary.
Is the textShouldEndEditing event supposed to be fired twice?

is it possible to change the style of uitableview in two different views? [duplicate]

This question already has answers here:
Can you programmatically change the style of a UITableView after it's been created? [duplicate]
(3 answers)
Closed 9 years ago.
i have a table and i have also declared its style as grouped table style in view did load but i also have a button on click of which i want to change the style of the same table.
initially i was setting this in view did load method:
tableObj= [[UITableView alloc]initWithFrame:CGRectMake(5,50,310,300)style:UITableViewStyleGrouped];
but on button click event i am setting tableview fram and style see below code
tableObj.frame=CGRectMake(5,50,310,300);
tableObj style=UITableViewStylePlain;
but it gives an error.....assignment to readonly property ??
According to the docs, UITableView's style property is declared thus:
#property(nonatomic, readonly) UITableViewStyle style
That readonly keyword means that you can get the value of the property, but you can't set it. You can only set the style when you create the table using -initWithFrame:style:. This agrees with the error message you received:
assignment to readonly property
Put simply, you can't do that.
tblView.style;
It is a read-only property you cannot set any value to while you can only read it which is set.. You can check whether the property is changable or, not by writing your code as below
[tblView setStyle:];
But you will find that you can't do that, so you can't set.
Better you get 2 tableviews, or, reinitialize your existing tableview with different style.
It possible to change the frame of table view dynamically but you can not change its style
You set the table style when you initialize the table view (see
initWithFrame:style:). You cannot modify the style thereafter.
UITableView Class Reference
You cannot change the table view style like that. My advice use two tables or do something like this.
Initially it is like this:
tableObj= [[UITableView alloc]initWithFrame:CGRectMake(5,50,310,300)style:UITableViewStyleGrouped];
Then when you want to change do this:
[tableObj removeFromSuperView];
tableObj=nil;]
//if not using ARC
[tableObj release];
tableObj= [[UITableView alloc]initWithFrame:CGRectMake(5,50,310,300)style:UITableViewStylePlain];
[self.view addSubview:tableObj];
According to the UITableView Class Reference, you can not change the style of a UITableView
When you create a UITableView instance you must specify a table style,
and this style cannot be changed.
See this.
Can you programmatically change the style of a UITableView after it's been created?
No this is not possible See this is wriiten in apple documentation:-

How do I make a certain area of my uitextfield non editable?

I have inserted an image on top of a uitextfield.A small image like you see in most login screens.The problem is the user can type in that area.How do I make that area non editable.So that the user can only type after that image
Seems that method - (CGRect)editingRectForBounds:(CGRect)bounds is what you are looking for UITextField Class Reference:
You should not call this method directly. If you want to provide a different editing rectangle for the text, you can override this method and return that rectangle. By default, this method returns a region in the text field that is not occupied by any overlay views.

UILabel.center is 0? how is that possible?

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

pagecontrol indicator custom image instead of Default

How can i change the color of pagination dots of UIPageControl?
In this link the sample code is given.But it shows 3 errors for me...
1'st ERROR:
Line:CGRect currentBounds = self.bounds;
Error:requst for member 'bounds' in something not a structure or union
Method:-(void)drawRect:
2nd Err: same error with same line in touchesBegan method.
3rd Err:#protocol PageControlDelegate
#optional
(void)pageControlPageDidChange:(PageControl *)pageControl;
#end
Error:Expected ')' before 'PageControl' .These are the three errors occurs for me...Please help me out to solve this..
I want to change the pagecontrol indicator(dot) color...
Thanks & Regards,
Renuga
first error is probably due to the fact that self does not refer to a view (a view controller maybe)
Second error is because PageControl is not yet defined by the time the parser come to your protocol definition.
Typical Class with delegate
#protocol MyProtocol;
#interface myClassWithDelegate
{
id<MyProtocol> _delagate;
}
#end
#protocol MyProtocol
-(void)MyClass:(MyClassWithDelegate*)c says(NSString*)message;
#end
I'm the one who wrote the sample code you are using.
I see that VdesmedT has already helped you on the syntax issues you were having. So +1 for that!
As for customizing the dots: The class as provided does not support custom images for the dots. It just draws circles using Core Graphics. The color of the circles is configured using the properties dotColorCurrentPage and dotColorOtherPage.
The default colors are grey dots with a black dot for the current page (because that is what I needed when I wrote it).
Let's say you want a red dot instead of a black dot for the current page and green dots for the other pages. When you create your PageControl instance you simply assign the properties like this:
pageControl.dotColorCurrentPage = [UIColor redColor];
pageControl.dotColorOtherPage = [UIColor greenColor];
... assuming your instance variable is called pageControl. Or use any of the other convenience/initialization methods for creating a UIColor that you like.
Hope this helps.