我对iOS Objective-C开发比较陌生,我遇到了一个无法找到解决方案的问题.
我有一个Table View Controller,上面有两个原型细胞,它们很好.这Table View Controller是三选一Tab Views,并且View发送到Tab Views有Navigation Controller.这意味着内部的视图Tab Views也有一个Navigation条.酒吧工作正常,按照预期的"后退"按钮,酒吧就位.但是,(至少在列表视图中)Navigation Bar未完全识别 - 它的标题不会出现,表格单元格直接从状态栏下方开始,而不是在导航栏下方.
这是一些显示问题的屏幕截图:
什么出现在Xcode中(我期望发生什么)
然后在设备上,这是实际出现的 - 后退按钮就位,工作正常,但没有标题字段,表格单元格开始太高.
我已经尝试添加Navigation Bar's了Navigation Items,虽然添加了一个Navigation Item允许我在Xcode中放置标题,但它仍然没有出现在测试设备上.我也尝试Navigation Controller在此视图之前添加另一个,但这也没有解决问题,并且它导致了heirachy中的导航问题.
希望我已经足够清楚了,请说如果我需要发布更多信息 - 我对Xcode比较新,所以不确定究竟什么是适用的,什么不适用.谢谢!
大家好。我正在创建一个简单的 SwiftUI 应用程序,我希望我的应用程序的 TabView 具有自定义背景而不是半透明的。
为了实现这一点,我使用UITabBar.appearance().backgroundColor = Colorand UITabBar.appearance().isTranslucent = false,它应该完全做到这一点,是的,它使栏不透明,但不是为栏提供我选择的颜色,而是在选项卡栏顶部生成一个新视图,该视图不是“不应该在那里,显然以前不存在。
您可以注意到出现的新视图。我想这是一个问题,isTranslucent因为当我删除它时,新视图消失了。
有没有办法可以更改颜色并使条形图不透明并且不显示该视图?
任何帮助表示赞赏。提前致谢。
SceneDelegate(仅更改颜色部分)
UITabBar.appearance().isTranslucent = false
UITabBar.appearance().backgroundColor = UIColor(named: "backgroundColor")
Run Code Online (Sandbox Code Playgroud)
标签视图
struct TabController: View {
@State private var selection = 0
var body: some View {
TabView(selection: $selection) {
HomePageView()
.tabItem {
Image(systemName: "house.fill")
.font(.title)
}
.tag(0)
Text("Second View")
.font(.title)
.tabItem {
Image(systemName: "bell.fill")
.font(.title)
}
.tag(1)
}
.edgesIgnoringSafeArea(.top)
}
}
Run Code Online (Sandbox Code Playgroud) 看起来Apple的TabView支持自动重新排列,但是在单击选项卡后它很快就会失去重新排列。
这是我的游乐场代码。
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
@State var arr = ["1","2","3","4","5","6"]
var body: some View {
TabView {
ForEach(self.arr, id: \.self) { name in
Text("Tab \(name) content")
.tabItem {
Image(systemName: "\(name).square.fill")
Text(name)
}
}
}
.font(.headline)
}
}
PlaygroundPage.current.setLiveView(ContentView())
Run Code Online (Sandbox Code Playgroud)
这是我在 gif 中执行的步骤。
我不确定这是否是一个 SwiftUI 错误,或者是否有一个我应该听的 onRearrange 钩子或者什么。
我正在尝试在我的tabbar中添加一个右键按钮navigationbar,它在iphone 5和5s设备以及所有模拟器中都能正常工作.但它没有出现在iphone 6和6+设备中.但它在iphone 6和6+的模拟器上工作正常.
这是按钮代码.
@property (nonatomic, weak) UIButton *rightButton;
-(void)setNavigationBarRightButton
{
rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(0, 0, 40, 40);
rightButton.layer.cornerRadius = 20;
rightButton.layer.borderColor = [[UIColor lightGrayColor] CGColor];
rightButton.layer.borderWidth = 2;
rightButton.imageView.layer.cornerRadius = 20;
rightButton.clipsToBounds = YES;
UIImage* image;
NSData* imageData = [[NSUserDefaults standardUserDefaults] objectForKey:@"image"];
if (imageData == (id)[NSNull null] || imageData.length == 0) {
NSLog(@"image data is %@",imageData);
image = [UIImage imageNamed:@"defaultIcon.png"];
}
else {
image = [UIImage imageWithData:imageData];
}
// rightButton.imageView.image = image;
[rightButton …Run Code Online (Sandbox Code Playgroud) 我使用 TabView PageTabViewStyle 和 SwiftUI 来显示页面视图,当我滑动这个 TabView 时,我发现子视图会多次调用 onAppear 方法,有人可以告诉我为什么吗?
这是我的代码
import SwiftUI
struct Pageview: View {
@StateObject var vm = PageViewModel()
var body: some View {
VStack {
DragViewBar().padding(.top, 14)
TabView(selection: $vm.selectTabIndex) {
TextView(index: "0").tag(0)
TextView(index: "1").tag(1)
TextView(index: "2").tag(2)
TextView(index: "3").tag(3)
TextView(index: "4").tag(4)
TextView(index: "5").tag(5)
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
}
}
}
struct TextView: View {
let index: String
var body: some View {
VStack {
Text(index)
}
.onAppear { print(index) }
}
}
struct DragViewBar: View {
var body: …Run Code Online (Sandbox Code Playgroud) 我有一个标签视图控制器,它有一个像这样的按钮,当它被按下时,会出现一个模态:
PostViewController *post = [[PostViewController alloc] init];
// [self.navigationController pushViewController:post animated:YES];
// Presentation
[self presentViewController:post animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
当模态完成后,我想解除它并推送一个新的视图控制器,如下所示:
ProfilesViewController *profile = [[ProfilesViewController alloc] init];
[self.navigationController pushViewController:profile animated:YES];
Run Code Online (Sandbox Code Playgroud)
但我不能在后vc作为它的模态.我该怎么做呢?
对于iPhone应用程序,如何以编程方式创建选项卡视图?任何人都可以通过提供一些很好的教程链接或示例来帮助我吗?
我知道这个问题已经被问过很多次了,但我的问题有些不同。
我正在单元格的内容视图中以编程方式创建一个 UIView 和一个 UIImageView 。当 TableView 第一次出现时它看起来很完美,但是当我向下和向上滚动时,这似乎重叠了。
不滚动的屏幕截图:
滚动后截图:
我遵循的代码:
viewForHead = [[UIView alloc]initWithFrame:CGRectMake(cell.viewForContents.frame.origin.x, cell.viewForContents.frame.origin.y-10, cell.viewForContents.frame.size.width, 45)];
viewForHead.backgroundColor = [UIColor colorWithRed:232.0/255.0 green:255.0/255.0 blue:16.0/255.0 alpha:1];
[cell.contentView addSubview:viewForHead];
UIImageView *imageViewForDP = [[UIImageView alloc]initWithFrame:CGRectMake(viewForHead.frame.origin.x-50, viewForHead.frame.origin.y-8, 60,60 )];
imageViewForDP.image = [UIImage imageNamed:@"dog_1.png"];
//[cell.viewForContents addSubview:imageViewForDP];
imageViewForDP.layer.cornerRadius = 30;
imageViewForDP.clipsToBounds = YES;
[viewForHead addSubview:imageViewForDP];
Run Code Online (Sandbox Code Playgroud)
请让我摆脱这个问题。谢谢