我在使用此功能时遇到问题,希望获得一些帮助。
我的层次结构是TabBarController-> Navigation Controller->TableViewController
我想要的是,如果您在当前选项卡上并且向下滚动,您将能够点击当前视图,UITabBarItem并且您将滚动回顶部,就像 Instagram 和 Twitter 那样。
我在这里尝试了很多事情:
但遗憾的是,没有一个答案适合我。
我真的很感激任何有关这种方式的帮助,提前谢谢您!
import UIKit
class BarsViewController: UITableViewController,UISearchResultsUpdating,UISearchBarDelegate,UISearchDisplayDelegate,UITabBarControllerDelegate{
//TableView Data & non related stuff....
override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
self.searchController.searchBar.resignFirstResponder()
self.searchController.searchBar.endEditing(true)
}
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let tabBarIndex = tabBarController.selectedIndex
if tabBarIndex == 0 {
let indexPath = IndexPath(row: 0, section: 0)
let navigVC = viewController as? UINavigationController
let finalVC = navigVC?.viewControllers[0] as? BarsViewController
finalVC?.tableView.scrollToRow(at: indexPath as …Run Code Online (Sandbox Code Playgroud) 我使用以下代码自定义背景颜色及其色调:
var blackBGColor = new UIColor(new nfloat(40) / 255f,
new nfloat(40) / 255f,
new nfloat(40) / 255f, 1f);
this.MoreNavigationController.TopViewController.View.BackgroundColor = blackBGColor;
var moreTableView = (UITableView)this.MoreNavigationController.TopViewController.View;
moreTableView.TintColor = UIColor.White;
foreach (var cell in moreTableView.VisibleCells)
{
cell.BackgroundColor = blackBGColor;
cell.TextLabel.TextColor = UIColor.White;
var selectedView = new UIView
{
BackgroundColor = UIColor.DarkGray
};
cell.SelectedBackgroundView = selectedView;
}
this.MoreNavigationController.NavigationBar.BarStyle = UIBarStyle.Black;
this.MoreNavigationController.NavigationBar.Translucent = false;
this.MoreNavigationController.NavigationBar.TintColor = UIColor.White;
this.MoreNavigationController.NavigationBar.BarTintColor = new UIColor(24f / 255f, 24f / 255f, 24f / 255f, 1f);
Run Code Online (Sandbox Code Playgroud)
但我无法改变里面的徽章颜色UIMoreNavigationController。
我试过这个: …
我在我的 iOS 应用程序中使用 SF Symbols 图像作为标签图像,方法如下:
self.tabBarItem.image = UIImage(systemName: "ellipsis")
Run Code Online (Sandbox Code Playgroud)
这导致所有图像顶部对齐,但我希望它们垂直居中。
我该怎么做?
如何设置标签栏颜色?例如,仅使用灰色条分配黑色结果。这是针对 SwiftUI 的。指定暗模式不是一个合适的解决方法。
struct ContentView: View {
@State private var selection = 1
init() {
UITabBar.appearance().backgroundColor = UIColor.blue
UITabBar.appearance().backgroundImage = UIImage()
//UITabBar.appearance().isTranslucent = false
//UITabBar.appearance().shadowImage = UIImage()
}
var body: some View {
TabView {
ClockView()
.tabItem {
Image("clock")
Text("Clock")
}.tag(0)
PlanetsNowView()
.tabItem {
Image("clock")
Text("Now")
}.tag(1)
SettingsView()
.tabItem {
Image("settings")
Text("Settings")
}.tag(2)
}
.accentColor(.white)
.opacity(1)
//.environment(\.colorScheme, .dark)
}
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的演示,仅创建了 UITabBarController 的子类并在故事板中设置。
我想在选择时将 TabBarButtonItem 的标题设置为橙色,在正常情况下将标题设置为黑色。以下代码在 iPhone 上的任何 iOS 版本上都可以正常工作,但在 iOS 15 的 iPad(设备和模拟器)上,所选颜色更改为蓝色和有线正常状态颜色。
这是苹果的错误还是我错过了什么?(我使用的是 Xcode13)
class CustomViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let tabBarAppearnace = UITabBarAppearance()
let tabFont = UIFont.boldSystemFont(ofSize: 18)
let selectedAttributes: [NSAttributedString.Key: Any]
= [NSAttributedString.Key.font: tabFont, NSAttributedString.Key.foregroundColor: UIColor.orange]
let normalAttributes: [NSAttributedString.Key: Any]
= [NSAttributedString.Key.font: tabFont, NSAttributedString.Key.foregroundColor: UIColor.black]
tabBarAppearnace.stackedLayoutAppearance.normal.titleTextAttributes = normalAttributes
tabBarAppearnace.stackedLayoutAppearance.selected.titleTextAttributes = selectedAttributes
tabBar.standardAppearance = tabBarAppearnace
}
}
Run Code Online (Sandbox Code Playgroud)
在 SwiftUI 中更改所选内容的颜色似乎相当困难UITabBarItem。为了在应用程序的中心位置定义设计,我尝试.appearance()这样做,但没有任何效果:
// Only effects the unselected items
UITabBar.appearance().unselectedItemTintColor = .red
// No effect, deprecated in iOS 8(!)
UITabBar.appearance().selectedImageTintColor = .cyan
// Only effects the title, not the icon
UITabBarItem.appearance().setTitleTextAttributes([.foregroundColor: UIColor.green], for: .normal)
// No effect
UITabBar.appearance().tintColor = .red
Run Code Online (Sandbox Code Playgroud)
View唯一有效的方法是不使用外观代理,而是使用SwiftUI 定义中的“手动”设置颜色.accentColor
struct MainView: View {
var body: some View {
TabView {
SomeView()
.tabItem {
Label("Main", systemImage: "list.dash")
.tint(.green) // No effect
}
.tint(.yellow) // No effect
}
.accentColor(.orange)
// No effect
//.tint(.red) …Run Code Online (Sandbox Code Playgroud) 我正在尝试复制UITabBarItem上使用的天真字体设置,以便在自定义标签栏上使用.
有谁知道字体设置是什么?什么UIFont,字体大小,文字颜色等......?
我创建了一个tabbar应用程序,我使用带有backGround图像的自定义TabBar.我已完成所有部件,但无法在点击时移除tabbar按钮的光晕(我只是在点击时更改UIButton选项,但仍然存在发光)
如何隐藏UITabBar按钮的光晕(即隐藏按钮的选择色调)?
现在TabBar是这样的..

需要tabBar这样的

我对tabbar项目的图像有问题.我在每个tabbar项目上设置了一个图像,但是当我运行应用程序时,出现的唯一图像是第一个tabbar项目的图像.在我选择其中一个选项卡之前,其他标签栏项目的图像不会显示.我用来在tabbar项目上设置图像的代码如下:
[self.tabBarItem setImage:[UIImage imageNamed:@"multi30x30.png"]];
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"multi30x30.png"]
withFinishedUnselectedImage:[UIImage imageNamed:@"multi30x30.png"]];
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?
uitabbaritem ×10
ios ×7
objective-c ×2
swift ×2
swiftui ×2
uitabbar ×2
c# ×1
fonts ×1
ios15 ×1
scrolltop ×1
sf-symbols ×1
uikit ×1
uitableview ×1
xamarin.ios ×1