Skip to content

Instantly share code, notes, and snippets.

View zeedark's full-sized avatar
💭
There.

Zeed Ark zeedark

💭
There.
View GitHub Profile
@zeedark
zeedark / gist:1639124
Created January 19, 2012 09:55
Resize a UIButton according to its title's length.
// Resize a UIButton according to its title's length.
CGSize stringSize = [self.myButton.titleLabel.text sizeWithFont:self.myButton.titleLabel.font];
CGRect frame = self.myButton.frame;
frame.size.width = stringSize.width;
[self.myButton setFrame:frame];
@zeedark
zeedark / gist:1690095
Created January 27, 2012 18:11
Displaying a right bar info button item
// Displaying a right bar info button item
UIButton *btn = [UIButton buttonWithType:UIButtonTypeInfoDark];
[btn addTarget:self action:@selector(doSomeAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.rightBarButtonItem = bbi;
[bbi release];
@zeedark
zeedark / gist:1690160
Created January 27, 2012 18:24
Display a right bar Close button item
// Display a right bar Close button item
UIBarButtonItem *bbi = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStyleBordered target:self action:@selector(doClose:)];
self.navigationItem.rightBarButtonItem = bbi;
[bbi release];
@zeedark
zeedark / gist:1690332
Created January 27, 2012 18:57
Horizontal flip transition of a modal view
// Horizontal flip transition of a modal view
MyViewController *av = [[[MyViewController alloc] init] autorelease];
[av setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[av setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentModalViewController:av animated:YES];
[av release];
@zeedark
zeedark / gist:1690396
Created January 27, 2012 19:11
Horizontal flip transition of a modal view with back button
//
// SomeViewController.m
//
- (IBAction)doShowSomething:(id)sender
{
UINavigationController *nav = [[[UINavigationController alloc]init] autorelease];
MyViewController *av = [[[MyViewController alloc] init] autorelease];
[nav pushViewController:av animated:NO];
@zeedark
zeedark / gist:1709849
Created January 31, 2012 10:45
Perform drawing-related operations on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
/* your code */
});
@zeedark
zeedark / gist:1730167
Created February 3, 2012 13:23
Change selected color of a UITableViewCell
cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
cell.selectedBackgroundView.backgroundColor = <your color>;
@zeedark
zeedark / gist:1730176
Created February 3, 2012 13:25
Change font color of a UITableCellView when selected
cell.textLabel.highlightedTextColor = <your color>;
@zeedark
zeedark / gist:1730218
Created February 3, 2012 13:41
Change UIButton title color
// Example for UIControlStateNormal
[yourbutton setTitleColor:<your color> forState:UIControlStateNormal];
// Example for UIControlStateHighlighted
[yourbutton setTitleColor:<your color> forState:UIControlStateHighlighted];
// And so on...
@zeedark
zeedark / gist:1744818
Created February 5, 2012 11:15
Trimming white spaces and new line characters from a NSString
// Trimming white spaces and new line characters from a NSString
NSString *s = @" hellow world. ";
NSString *trimmedString= [s stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];