When you create a new UIView XIB in Interface Builder, it is by default full-screen. Width and height cannot be changed, they are dimmed out. What to do?
Switch to Simulated Metrics and change "Status Bar" from default (gray) to None. Now you can edit the size!
First time this was difficult to discover, second time I kind of recalled what to do and now it's all so plain obvious :)
Showing posts with label UIView. Show all posts
Showing posts with label UIView. Show all posts
Wednesday, April 20, 2011
How to Change UIView Size in Interface Builder
Easy Way to Debug UIView Hierarchy
Do you want to see complete view hierarchy for debugging purposes? There is an easy way to do it, provided by Apple - totally unofficially!
Actually official documentation says it's undocumented and not supported. No problem with that. Very kind of Apple, good developer service!
Actually official documentation says it's undocumented and not supported. No problem with that. Very kind of Apple, good developer service!
Wednesday, March 30, 2011
How to Change UITextView Background Color
You have UIView, which contains UITextView with some text. This is how to change UITextView background color:
self.view.opaque = YES;Not what I was looking for, but might as well write down, looks useful enough. Another tool in the toolbox, even though everything still looks like a nail.
self.view.backgroundColor = [UIColor yellowColor];
self.textView.opaque = NO;
self.textView.backgroundColor = [UIColor clearColor];
self.textView.textColor = [UIColor orangeColor];
Labels:
clearColor,
opaque,
UIColor,
UITextView,
UIView
Sunday, March 27, 2011
Hide UITableView Empty Cell Separator Lines
Plain UITableView displays cell separator lines, when table is empty or has only a few real cells. This is the default behaviour - and it is good. You should not change it.
But sometimes it looks a bit too weird. When your cells have different heights, all empty cells following the last real one will use last cell's height. If this changes at every table refresh, the "jumping" empty cells start annoying users. Or at least developers.
But sometimes it looks a bit too weird. When your cells have different heights, all empty cells following the last real one will use last cell's height. If this changes at every table refresh, the "jumping" empty cells start annoying users. Or at least developers.
Labels:
CGRectZero,
separatorStyle,
tableFooterView,
UITableView,
UITableViewCell,
UIView
Monday, February 21, 2011
How to Find MFMailComposeViewController Email Addresses
One of the missing iOS APIs is a way to find out whom did user send email to. Otherwise MFMailComposeViewController is excellent: easy to setup, easy to launch, easy to use and easy to close. You just have no idea what user was doing with it!
I really needed to know who were email recipients. There are several good reasons for this and I just had one of those. So it was time to do some experimenting!
I really needed to know who were email recipients. There are several good reasons for this and I just had one of those. So it was time to do some experimenting!
Labels:
appendString,
didFinishWithResult,
isKindOfClass,
mailComposeController,
MFMailComposeResult,
MFMailComposeViewController,
NSLog,
NSMutableString,
NSString,
stringWithCapacity,
UITextField,
UIView
Thursday, October 14, 2010
How to Control UISearchBar Background Color
When you have a list, you want to search it. How would you do that? No, don't code it by yourself. Done it, removed it.
By default each UITableView comes with search support via a built-in UISearchDisplayController. You just add and connect UISearchBar to your table in Interface Builder and provide some delegate methods to make it work. Pretty easy:
You can fix that by doing two things. First get rid of default background:
Sad to think how many hours I wasted experimenting Things That Will Not Work, just to find out that kind of miniscule solution. Also bet that this will not work one year from now...
By default each UITableView comes with search support via a built-in UISearchDisplayController. You just add and connect UISearchBar to your table in Interface Builder and provide some delegate methods to make it work. Pretty easy:
self.searchDisplayController.delegate =Controlling how your UISearchBar looks like is a bit more difficult. If you want to show search box and some other component(s) side by side, you can do it by putting UIToolbar at back and a short UISearchBar on top of it. By default their backgrounds are different, looking pretty ugly together. Like a hack, what it really is.
self.searchDisplayController.searchBar.delegate =
self.searchDisplayController.searchResultsDataSource =
self.searchDisplayController.searchResultsDelegate = self.mySearchObject;
You can fix that by doing two things. First get rid of default background:
for (UIView *view in self.searchBar.subviews)...and the second thing? Something that will be extremely hard to find out, unless you get it right by accident? You have to set UISearchBar style Black Translucent!
{
if ([view isKindOfClass:NSClassFromString
(@"UISearchBarBackground")])
{
[view removeFromSuperview];
break;
}
}
Sad to think how many hours I wasted experimenting Things That Will Not Work, just to find out that kind of miniscule solution. Also bet that this will not work one year from now...
Labels:
delegate,
interface builder,
isKindOfClass,
NSClassFromString,
UISearchBarBackground,
UISearchDisplayController,
UITableView,
UIToolbar,
UIView
Monday, May 3, 2010
How to Create Delayed Tab Change
Not sure, if it's a good idea, but this is how you create "smooth" tab view changes:
Be careful, style is not an easy thing to achieve!
User will notice something happened as expected and your app will look either stylish or slow, depending on your graphics, UI design and overall implementation.#pragma mark - TabBar controller delegate - (void)tabBarController:(UITabBarController*)tbc didSelectViewController:(UIViewController*)newSelection { [UIView beginAnimations:@"myTabFade" context:nil]; [UIView setAnimationDuration:0.5]; for (UIViewController* vc in tbc.viewControllers) vc.view.alpha = (vc==newSelection) ? 1 : 0; [UIView commitAnimations]; }
Be careful, style is not an easy thing to achieve!
Labels:
alpha,
animation,
delegate,
iphone,
UITabBarController,
UIView,
UIViewController
Friday, March 19, 2010
Accessing Unknown 'backgroundColor' Component of a Property
Embarrassing problem. Forgot to import the header file or add class forward declaration. Somehow you'd expect those to happen automatically, don't you think?
Code works as-is right after import has been done. Just adding this reminder for google to find next time.
Code works as-is right after import has been done. Just adding this reminder for google to find next time.
Monday, March 15, 2010
Interface Builder cannot change UIView color
If you fail to change UIView color in Interface Builder, it could be because Emulator is blocking your changes. Close emulator and try again.
Wednesday, February 10, 2010
How to Do Totally Custom Titlebar
iPhone SDK does not support a "titlebar" with custom background image, fully visible title text and titlebar buttons.
You can create semi-transparent UINavigationBar or UIToolbar (style Black Translucent) to see custom background (UIView just below), but your image is still dimmed. You can tune Alpha value between 1 and 0, but at the same time your title text and buttons visibility change, too.
Another solution is to create a custom setup, which just looks like a titlebar:

Inherit your own MyToolbar class from UIToolbar. Place on it 3 UIBarButtonItems: one for left side button, one Flexible Space UIButton in middle and one for right side button. The middle flexible sized button should push your other button to correct locations. If not, change it to fixed size and reside as you wish. Your number of button can also differ, naturally. I used 5.
Here's the full source code for your class:
Place a UILabel on top of your toolbar, resize to fit the available space between other buttons. Change font e.g. Helvetica Bold size 18, color red, , shadow black and background transparent (opacity 0%).
You can create semi-transparent UINavigationBar or UIToolbar (style Black Translucent) to see custom background (UIView just below), but your image is still dimmed. You can tune Alpha value between 1 and 0, but at the same time your title text and buttons visibility change, too.
Another solution is to create a custom setup, which just looks like a titlebar:

Inherit your own MyToolbar class from UIToolbar. Place on it 3 UIBarButtonItems: one for left side button, one Flexible Space UIButton in middle and one for right side button. The middle flexible sized button should push your other button to correct locations. If not, change it to fixed size and reside as you wish. Your number of button can also differ, naturally. I used 5.
Here's the full source code for your class:
#import
@interface MyToolbar : UIToolbar {
}
@end
#import "MyToolbar.h"
@implementation MyToolbar
- (void)drawRect:(CGRect)rect
{
// Warning: Hardcoded for portrait size
UIImage *image = [[UIImage imageNamed:@"sample.png"] retain];
[image drawInRect:rect];
[image release];
}
@endPlace a UILabel on top of your toolbar, resize to fit the available space between other buttons. Change font e.g. Helvetica Bold size 18, color red, , shadow black and background transparent (opacity 0%).
Labels:
iphone,
UIBarButtonItem,
UILabel,
UINavigationBar,
UIToolbar,
UIView
Subscribe to:
Posts (Atom)





