English 中文(简体)
自定义 UITabBar 和 View 主计长间空间
原标题:Space between custom UITabBar and ViewController

I took a regular UITabBar and changed it s background image to a custom one which has a lower height, so I changed the height of the frame. At first what I got is a blank space below the tab bar. so I changed the origin of the frame too. But now the blank space has moved up above the tab bar and this is the result:

"https://i.sstatic.net/xPl7e.png" alt="标签栏以上的空间"/>

这是在AppDelegate中宣布标签栏的代码:

self.tabContoller = [[UITabBarController alloc] init];
//customizing the tabbar
UIImage * tabBackgroundImage = [UIImage imageNamed:@"tabBarBg.png"];
self.tabContoller.tabBar.backgroundColor = [UIColor colorWithRed:245.f/255.f green:245.f/255.f blue:245.f/255.f alpha:255.f/255.f];
self.tabContoller.tabBar.backgroundImage = tabBackgroundImage;
//setting the tabbar height to the correct height of the image
CGRect tabR = self.tabContoller.tabBar.frame;
CGFloat diff = tabR.size.height - tabBackgroundImage.size.height;
tabR.size.height = tabBackgroundImage.size.height;
tabR.origin.y += diff;
self.tabContoller.tabBar.frame = tabR;

我想问题在于 Viewcurrent 将自己拖上一个常数空格上方, 这个常数空格是常规制表栏的高度。 是否有办法改变它?

最佳回答

将您的 UITabBar 控制器的子视图转换成一个完整的框架,

[[yourTabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 480)];
问题回答

尝试从 UITabBar 中创建您自己的类,然后使用此函数 :

- (CGSize)sizeThatFits:(CGSize)size {
    CGSize auxSize = size;
    auxSize.height = 54; // Put here the new height you want and that s it
    return auxSize;
}

这将将 UITabBar 的大小调整为您想要的大小。 简单易行 。

如果像@JoaT 所提到的那样更改框架, 无法确保查看控制器视图有正确的自动化掩码设置 。

此 < a href=" "https://stackoverflow.com/ questions/2037716/laying-out-sizing- subviews- in- a- uiviewcontler > > >SO 链接可能有用 。

我尝试了改变制表板的高度和来源, 对我来说,它很有效。 你可以尝试提高你的视觉控制器的高度。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签