I want to make a uiview that can be aware of highlight status, like a UILabel is when put inside a UICellTableView.
Subclass UIControl instead of UIView.
Related
I know you can create a UISearchBar, put it in a UIBarButtonItem, and set that as the rightBarButtonItem in code, but I was wondering if there was a way to do that in IB now? Thanks!
You can place an UIView inside UIBarButtonItem. You can then place any UIView subclass into that UIView as subview.
I have a uilabel (and other labels as well) inside a uiview.
I added a gesture that when the label is tapped on I perform some ibaction.
The action is not triggered, however if i place the label outside the uiview (meanning it's not a child of the uiview) than it works fine. I placed it back inside the view than it's stop triggering the action.
any idea why?
something when the label is inside the uiview makes it not react to the gesture and I'm not sure why (despite the fact that both the uiview and the label have 'User interaction enabled).
TIA
Or just not have a UILabel and have only the text of the button be visible, that way you dont have to have a UILabel and a UIButton (from a memory perspective).
I think the problem here is that the UILabel is receiving the touch event instead of the UIView. Try adding the following code (modified to fit your label, of course) to the viewDidLoad method:
myLabel.userInteractionEnabled = FALSE;
This should allow touch events to pass through to the UIView. Why are you doing this? Might it not be easier to work with a UIButton?
apparently there was an issue with the parent control, I redrew the View and it worked fine. Thanks for your comments.
I've added a functionality to UIView by extending drawRect.
This works great for a simple UIView, but the problem is that I want it to work also for UILabel, UIButton, UIImageView and every other component that inherits from UIView.
I was wondering what is the best way to achieve this. Can I make a subclass of UILabel (for example) that inherits from MyView instead of UIView?
You can make a category of UIView and override drawRect function, so all subclasses of UIView, that call to [super drawRect:...] will use this category function, though you should be extremely cautious while doing this, since you override something very basic there. I did it at time with UINavigationBar when I would need to add a background picture there. But take into consideration that not all subclasses of UIView call [super drawRect:...].
I have a subclass of UIControl and within the control I am adding a UILabel and UIImageview to constitute my button.
As a subclass of UIControl, I believe I am unable to utilize the method '[doSomethingButton setBackgroundImage:stretchableButtonImagePressed
forState:UIControlStateHighlighted]' to set the the UIControl to a different image when clicker
How can I mimic a button's reaction to a user's touch i.e. (UIControlStateHighlighted)
Yes, you are right, the setBackgroundImage:ForState method is a method for UIButton.
The easiest to achieve your goal would be to update the imageView && label states in the action selector of your UIControl.
A subclass do all the works which original works. You can directly set the UIImage for highlighted state to your subclassed control.
Basically I want to re-style UITableView(Controller). Each cell will have a picture as a background and such. this tableview will be used throughout the app thats why I want to subclass it, because I want to be able to define the style once and then reuse it everywhere, but still be able to change things per view. For instance, I'd like every cell to have the same blue background and a specific font, but I might want to change the font in one view, or make the cell taller/shorter. You get the idea.
Can I subclass UITableViewController and create the style in the methods in that? Then subclass MyCustomUITableViewController when I want to create a table view? Or would it better to subclass UITableView and then [self.view addSubview:(MyCustomTableView *)tableVie]?
Thanks
Tom
You will probably want to subclass UITableViewController to define relevant UITableViewDelegate methods, but I think that the real work will be in subclassing UITableViewCell to get the look that you want.
UITableViewCell is a UIView, so it can have a background color and it can contain a UILabel, for example.
Your -tableView:cellForRowAtIndexPath: will need to instantiate your UITableViewCell subclass (or load it from a nib) - and then configure it appropriately. I.e., setting text, image, font, etc.
Hope this helps.