将UINavigationBar更改为透明色

时间:2017-02-18 09:11:07

标签: ios swift xcode storyboard

我希望我的UINavigationBar完全透明,除了标题和我添加的按钮。

我似乎无法使其发挥作用。我已经尝试了一切。这对我来说最有意义:

override func viewDidLoad() {
    self.title = "CURRENT BALANCE"

    self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController!.navigationBar.shadowImage = UIImage()
    self.navigationController!.navigationBar.isTranslucent = true

    self.setupSideMenu()

    self.topUpButton.asCircle()
    self.exchangeButton.asCircle()
    self.lockButton.asCircle()
}

enter image description here

3 个答案:

答案 0 :(得分:1)

这是我的OC代码,使UINavigationBar完全透明:

首先将VC设置为- (void) navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated,然后覆盖 // change the backgroudcolor black self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.000 green:0.000 blue:0.000 alpha:1.000]; // change the alpha 0.3 self.navigationController.navigationBar.alpha = 0.300; // change the translucent YES self.navigationController.navigationBar.translucent = YES;

self.view.backgroudcolor

主要是,检查您的代码UINavigationBar,如果UINavigationBar下的任何视图有背景颜色,您的package tas.module1; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.BlockLocation; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.FSDataOutputStream; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; public class JavaClient { public JavaClient() { } public static void main(String[] args) throws IOException { JavaClient jc = new JavaClient(); Configuration config = new Configuration(); config.addResource(new Path("/usr/local/hadoop-2.7.1/etc/hadoop/core-site.xml")); config.addResource(new Path("/usr/local/hadoop-2.7.1/etc/hadoop/hdfs-site.xml")); config.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName() ); config.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName() ); FileSystem dfs = FileSystem.get(config); String dirName = "TestDirectory"; System.out.println(dfs.getWorkingDirectory() +" this is from /n/n"); Path src = new Path(dfs.getWorkingDirectory()+"/"+dirName); dfs.mkdirs(src); System.out.println("created dir"); dfs.close(); } } 将显示视图的颜色。

答案 1 :(得分:1)

设置导航栏的背景颜色属性

self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: UIBarMetricsDefault)

更新

extension MutableCollection where Self : RandomAccessCollection {
    /// Sort `self` in-place using criteria stored in a NSSortDescriptors array
    public mutating func sort(sortDescriptors theSortDescs: [NSSortDescriptor]) {
        sort { by:
            for sortDesc in theSortDescs {
                switch sortDesc.compare($0, to: $1) {
                case .orderedAscending: return true
                case .orderedDescending: return false
                case .orderedSame: continue
                }
            }
            return false
        }

    }
}

extension Sequence where Iterator.Element : AnyObject {
    /// Return an `Array` containing the sorted elements of `source`
    /// using criteria stored in a NSSortDescriptors array.

    public func sorted(sortDescriptors theSortDescs: [NSSortDescriptor]) -> [Self.Iterator.Element] {
        return sorted {
            for sortDesc in theSortDescs {
                switch sortDesc.compare($0, to: $1) {
                case .orderedAscending: return true
                case .orderedDescending: return false
                case .orderedSame: continue
                }
            }
            return false
        }
    }
}

答案 2 :(得分:1)

这是swift 4的透明NavigationController代码:

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationBar.shadowImage = UIImage()
    self.navigationBar.isTranslucent = true
}