[英]swiftUI -I want to move the position of the item in the tabbar
我要對齊圖2紅框內項目的頂部position,如圖1所示。
選擇項目時,圖像會自動對齊。 有沒有辦法根據圖像頂部從標簽欄浮動填充?
您可以使用 UIEdgeInsets 調整 tabBar 項目的空間,如下所示:
let items = tabBarCnt.tabBar.items
for item in items!
{
item.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
}
您可以使用此代碼移動 Image 的 position。 如果您在該圖像中使用了標題,那么您應該使用該標題代替 nil。
擴展 UITabBarController {
override open func viewDidLayoutSubviews() {
let items = tabBar.items
for item in items!
{
if item.title == nil {
item.imageInsets = UIEdgeInsets(top: -20, left: 0, bottom: 10, right: 0)
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.