Рецепты по работе с дизайном в iOS

Фон

Замостить фон картинкой:

self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg.png"]];

TabBar

Сделать иконки таббара оригинального цвета (как сама картинка) и сделать цвет выбора для двух иконок

- (void)settingTabBarItem
{
    [self.tabBarItem setImage:[[UIImage imageNamed:@"home.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [self.tabBarItem setSelectedImage:[[UIImage imageNamed:@"home.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]];
    [self.tabBarController.tabBar setTintColor:selectedColor];
    [self.tabBarController.tabBar setSelectedImageTintColor:selectedColor];
    
    UITabBarItem *item1 = self.tabBarController.tabBar.items[1];
    item1.image = [[UIImage imageNamed:@"star.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; // unselected image
    item1.selectedImage = [UIImage imageNamed:@"star.png"]; // selected image
    
}

Изменить цвет таббара

self.tabBarController.tabBar.barTintColor = [UIColor tabBarColor];

Статус бар

Изменить цвет статус бар на белый

В info.plist добавить View controller-based status со значением NO

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

Высота

[UIApplication sharedApplication].statusBarFrame.size.height

Высота экрана (в зависимости от ориентации)

-(CGRect) getScreenRect
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    if(orientation == UIInterfaceOrientationLandscapeRight || orientation==UIInterfaceOrientationLandscapeLeft)
        screenRect = CGRectMake(screenRect.origin.x, screenRect.origin.y, screenRect.size.height, screenRect.size.width);
    else
        screenRect = CGRectMake(screenRect.origin.x, screenRect.origin.y, screenRect.size.width, screenRect.size.height);
    return screenRect;
}

Кнопка назад — сделать белой, а не синей

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationController.navigationBar.backItem.backBarButtonItem = backButton;
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [self.navigationController.navigationBar.topItem setTitle:@""];

Убрать клаву в поиске

tap = [[UITapGestureRecognizer alloc]
                                   initWithTarget:self
                                   action:@selector(dismissKeyboard)];

- (void) dismissKeyboard
{
    // add self
    [searchBar resignFirstResponder];
    
    [self.view removeGestureRecognizer:tap];
}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    [self.view addGestureRecognizer:tap];
    return YES;
}

Узнать какие есть шрифты

You need to edit .plist file. Add «Fonts provided by application» key into your plist and in Item 0copy the exact filename of the font you copied to your Supporting files WITH extension. For example: «JosefinSansStd-Light_0.otf»
Objective-C

NSArray *fontFamilies = [UIFont familyNames];
    for (int i = 0; i < [fontFamilies count]; i++)
    {
        NSString *fontFamily = [fontFamilies objectAtIndex:i];
        NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
        NSLog (@"%@: %@", fontFamily, fontNames);
    }

Swift

        let fontFamilies:NSArray  = UIFont.familyNames() as NSArray
        for i in 0...fontFamilies.count
        {
            let fontFamily:NSString = fontFamilies.objectAtIndex(i) as NSString
            let fontNames:NSArray = UIFont.fontNamesForFamilyName(fontFamily)
            println("\(fontFamily)  \(fontNames)")
        }

Закруглить углы картинки

cell.cellImage.layer.cornerRadius = 15;
cell.cellImage.clipsToBounds = YES;

НавБар

Изменить цвет навбара бар

self.navigationController.navigationBar.barTintColor = [UIColor navBarColor];
self.navigationController.navigationBar.translucent = NO;

Анимация появления(изчезания)

UIView animateWithDuration:0.4 delay:0 options:0 animations:^{
                    downloadedImageView.alpha = 1.0f;
                } completion:^(BOOL finished) {}];