从UISearchController搜索栏中移除黑色边框swift

时间:2016-07-31 03:49:10

标签: ios swift

我的tableView中有一个UISearchController。另请注意,顶部有一个导航项。 我的问题是,当我加载页面时,我在顶部和底部有一个黑色边框,但是,当我点击搜索栏时它不存在。

页面加载时的搜索栏(带黑色边框):

enter image description here

点击搜索栏(没有黑色边框)后:

enter image description here

以下是相关代码:

let searchController = UISearchController(searchResultsController: nil)

在viewDidLoad中:

searchController.searchBar.barTintColor = UIColor.redColor()
        searchController.searchBar.tintColor = UIColor.whiteColor()

我遵循了几个类似的问题,并在viewDidLoad()中的上述行之后进行了以下更改:

1)searchController.searchBar.backgroundImage = UIImage()

2)searchController.searchBar.searchBarStyle = UISearchBarStyle.Minimal

3)searchController.searchBar.layer.borderColor = UIColor.clearColor().CGColor

4)

 searchBar.layer.borderWidth = 1
    searchBar.layer.borderColor = UIColor.whiteColor().CGColor

没有用。这是我使用代码的顺序的问题,或者我将如何摆脱这些线?

3 个答案:

答案 0 :(得分:5)

经过大量搜索后解决了这个问题。这是我如何做到的。在viewDidLoad中,添加了以下行:

self.searchController.searchBar.translucent = false
    self.searchController.searchBar.backgroundImage = UIImage()
    self.searchController.searchBar.barTintColor = UIColor.redColor()
    self.searchController.searchBar.tintColor = UIColor.whiteColor()

之后在didFinishLaunchingWithOptions的app.delegate文件中添加了以下代码:

let backgroundColor = UIColor.redColor()
        let foregroundColor = UIColor.whiteColor()


        UIApplication.sharedApplication().statusBarStyle = .LightContent

        UINavigationBar.appearance().shadowImage = UIImage()

        UINavigationBar.appearance().setBackgroundImage(backgroundColor.toImage(), forBarMetrics: UIBarMetrics.Default)

        UINavigationBar.appearance().tintColor = foregroundColor

        UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: foregroundColor]

还需要在app.delegate文件上放置此扩展名(位于类之外)

extension UIColor{
    func toImage() -> UIImage {
        let rect = CGRectMake(0, 0, 1, 1)
        UIGraphicsBeginImageContextWithOptions(rect.size, true, 0)
        self.setFill()
        UIRectFill(rect)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }
}

(感谢Noel从enter image description here获得的延期)

最后,期望的结果:

this answer

答案 1 :(得分:0)

我认为这是您需要删除边框的导航栏。

How to hide iOS7 UINavigationBar 1px bottom line

答案 2 :(得分:0)

对于iOS 13 / Swift 5;下列代码可以解决问题:

<html>
<h1> Welcome to Doctor Scheduler </h1>
<body>

Please enter your details so we can fit you in.


<form action = "" method="post">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name"><br>
<label for="address">Address:</label><br>
<input type="text" id="address" name="address"><br>
<input type="checkbox" id="status" name="status" value="New">
<label for="status">Check if you are a new patient</label><br><br>

<label for="appt">Choose a time for your meeting:</label>

<input type="time" id="appt" name="appt"
       min="06:00" max="18:00" required></br>

Office hours are 6am to 6pm<br><br>

    <input type="submit" name="buttonSubmit" value="Submit" />
</form>


<?php


    if($_SERVER['REQUEST_METHOD'] == "POST" and isset($_POST['buttonSubmit']))
    {
        $array =
        $temp = array('Name'=>$_POST['name'], 'Address'=>$_POST['address'],'Status'=>$_POST['status'], 'TimeSlot'=>$_POST['appt']);
        array_push($array, $temp);

        write_array($array);
        echo new_table($array);
    }

    function new_table($array)
    {
    echo '<table cellpadding="5" cellspacing="5" border="2">';

    foreach($array as $temp) { 
        echo '<tr>';
        echo '<td>' . $temp['Name'] . '</td>';
        echo '<td>' . $temp['Address'] . '</td>';
        echo '<td>' . $temp['Status'] . '</td>';
        echo '<td>' . $temp['TimeSlot'] . '</td>';
        echo '</tr>';
    }

    echo '</table>';
}
    function write_array($array)
    {
        /*$string = serialize($array);
        $fn = 'patients.txt';
        $fh = fopen($fn, 'w');
        fwrite($fh, $string);
        fclose($fh);*/

        $fp = fopen('patients.txt', 'w');
        fwrite($fp, print_r($array, TRUE));
        fclose($fp);
    }
?>

</html>

干杯!