iphone 开发小技艺备忘

iphone 开发小技巧备忘
1. 在uiviewcontroller声明nsstring property的方法:
NSString *groupName;
@property (nonatomic, assign) NSString *groupName;

2.Setting the back button title of a UINavigationItem
The following code will set the back button title of the current UINavigationItem:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationItem setBackBarButtonItem:backButton];
[backButton release];


The target: and action: parameters are definitely ignored (replaced by the default back button behavior) and the style also seems to be ignored because the back button retains its pointed left side.

This next block of code looks like it should do the same thing but does not work:

self.navigationItem.backBarButtonItem.title = [NSString stringWithString:@"Back"];

注意:一定要在当前页面设置backbarbuttonitem!!
MAJOR CAVEAT: As pointed out in this thread, "the back button is 'owned' by the previous view on the stack." In other words, the setBackBarButtonItem method should be called on the view that the user is navigating away from, rather than the view above which this button is actually displayed.

3. 调整tableviewcell 背景色

UITableViewCell *bgView = [[UITableViewCell alloc] initWithFrame:CGRectZero];
    bgView.backgroundColor=indexPath.row % 2? [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1]: [UIColor whiteColor];
    bgView.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"disclosure.png"]];
    cell.backgroundView=bgView; 
    return cell;


4. ipad 背景透明

tableView.backgroundColor = [UIColor clearColor];
在iPhone上可以透明,但是在iPad上无效,
解决方案:ttable.backgroundView.alpha = 0;

5. 图标 资源
Ever reach a brick wall in designing your app due to a shortage of artwork? I ran into this situation this morning, and figured I’d share what I’ve found for others that might be similarly design handicapped.

iPhone Tab Bar Icons
GlyFX has a few sets available for purchase at http://www.glyfx.com/shop/listing/iphone/
GLYPHISH has a large set for free at http://glyphish.com/
Quality Icons Blog has a few free gaming focused icons available here http://qualityicons.blogspot.com/2009/08/iphone-tab-bar-gaming-icons.html
eddit has a 160+ icon set you can purchase here http://www.eddit.com/shop/iphone_ui_icon_set/
kombine has a 130+ icon set for sale at http://www.kombine.net/icon-store/iphone-tab-bar-icons
Just remember your app can get rejected for the incorrect use of icons or breaking the iPhone Human Interface Guidelines. I found the blog post “icon fail” by Under the Bridge extremely helpful in understanding the importance of selecting your icons.

6. How to make your own tab bar icon
http://www.youtube.com/watch?v=YUWMeJq9f-8
http://www.aha-soft.com/faq/ios-toolbar-icons.htm
http://speckyboy.com/2010/04/30/iphone-and-ipad-development-gui-kits-stencils-and-icons/

7. 各种图标尺寸
http://www.axialis.com/tutorials/make-ipad-icons.html#t2

8. Resizing a UITableViewCell to Hold Variable Amounts of Text
http://www.raddonline.com/blogs/geek-journal/iphone-sdk-resizing-a-uitableviewcell-to-hold-variable-amounts-of-text/

9. RoundedUITableView for iOS
http://www.cocoacontrols.com/platforms/ios/controls/roundeduitableview

10. 从navigationcontroller隐藏toolbar时隐藏动画会产生阴影,解决办法时不使用navigationcontroller自带的toolbar,自己在uiview中添加toolbar:
- (void)viewDidLoad
{
    // Add a toolbar to the view
    CGRect toolbarFrame = CGRectMake(0, 372, 320, 44);
    UIToolbar *myToolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame];

    UIBarButtonItem *compassButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"compass.png"]
                                                                      style:UIBarButtonItemStyleBordered
                                                                     target:self
                                                                     action:@selector(zoomToCurrentLocation)];

    compassButton.width = 30.0f; // make the button a square shape
    [myToolbar setItems:[NSArray arrayWithObject:compassButton] animated:NO];
    [compassButton release];

    [self.view addSubview:myToolbar];
    [super viewDidLoad];
}


11. How to compare if two objects are really the same object?
The == operator tests whether the two expressions are the same pointer to the same object. Cocoa calls this relation “identical” (see, for example, NSArray's indexOfObjectIdenticalTo:).

To test whether two objects are equal, you would send one of them an isEqual: message (or a more specific message, such as isEqualToString:, if it responds to one), passing the other object. This would return YES if you really only have one object (equal to itself, obviously) or if you have two objects that are equal. In the latter case, == will evaluate to NO.

12. IOS支持的所有字体 font
http://iosfonts.com/

13. Advanced App Tricks
http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html

14. 输入密码界面:
https://github.com/Koolistov/Passcode

http://code.google.com/p/kpasscode/

15. 程序和iTunes间共享文件
http://www.alterplay.com/ios-dev-tips/2010/11/file-sharing-from-app-to-itunes-is-too-easy.html

16. http://*.com/questions/7989968/iphone-loading-view-slide-effect