小编Pet*_*Pik的帖子

在swift中删除navigationBar中的边框

我一直试图删除navigationBars边框没有运气.我已经研究过,人们似乎告诉将shadowImage和BackgroundImage设置为nil,但这在我的情况下不起作用.

我的代码

    self.navigationController?.navigationBar.barTintColor = UIColor(rgba: "#4a5866")
    self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: ""), forBarMetrics: UIBarMetrics.Default)
    self.navigationController?.navigationBar.shadowImage = UIImage(named: "")
Run Code Online (Sandbox Code Playgroud)

插图:

在此输入图像描述

iphone uinavigationbar ios swift

105
推荐指数
15
解决办法
6万
查看次数

透明导航栏ios

我正在创建一个应用程序,我已经在互联网上浏览了,我想知道他们是如何制作这样的透明导航栏的:

在此输入图像描述

我在我的appdelegate中添加了以下内容:

UINavigationBar.appearance().translucent = true
Run Code Online (Sandbox Code Playgroud)

但这只是让它看起来如下:

在此输入图像描述

如何使navigationBar像第一张图像一样透明

iphone uinavigationbar ios swift

99
推荐指数
9
解决办法
13万
查看次数

将自定义对象保存到NSUserDefaults中

我有新闻ViewControllerTeamViewController.所述TeamViewController含有选择加入到阵列时teamObjects的的tableView.我想添加这个数组,NSUserDefaults所以我可以从NewsController包含url请求的地方访问它们,其中需要teamObjects.但是我一直得到:

'尝试为关键团队插入非属性列表对象("")

如果有更好的方法而不是存储它,我愿意接受其他建议 NSUserDefaults

didSelectRowAtIndexPath 方法

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: true)


    let team = self.teamArray[indexPath.row] as Team
    var removed = false

    for (index, value) in enumerate(self.teamSelected) {
        if (value == team) {
            self.teamSelected.removeAtIndex(index)
            removed = true
        }
    }

    if (!removed) {
        self.teamSelected.append(team)
    }

    var userDefaults = NSUserDefaults.standardUserDefaults()
    userDefaults.setValue(self.teamSelected, forKey: "teams")
    userDefaults.synchronize()

    tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)

我的目标

class Team: NSObject{
    var id: Int!
    var name: NSString!
    var …
Run Code Online (Sandbox Code Playgroud)

nsuserdefaults ios swift

67
推荐指数
2
解决办法
7万
查看次数

brew install npm"npm:command not found"

我已经安装了节点使用brew install node,当我使用时,node -v我得到了以下内容v5.0.0.但是,当我尝试运行npm命令时,我得到了npm: command not found.

我试图跑brew install npm,但我得到了以下回应node-5.0.0 already installed.

它发生在节点也返回命令未找到,但我通过运行修复brew link node,但是npm仍然似乎不起作用.

我该如何解决这个问题?

bash node.js npm osx-elcapitan

38
推荐指数
3
解决办法
3万
查看次数

通过navigationController通过segue传递数据

我正在尝试将数据从一个viewController推送到另一个.我已将viewController连接到另一个ViewController的navigationController,然后将标识符设置为"showItemSegue".我在这两行中出错:

var detailController = segue.destinationViewController as ShowItemViewController
detailController.currentId = nextId!
Run Code Online (Sandbox Code Playgroud)

图示:

在此输入图像描述

代码:

override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {


    nextId = itemArray?.objectAtIndex(indexPath.row).objectForKey("objectId") as? NSString

    self.performSegueWithIdentifier("showItemSegue", sender: self)

}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {

    if (segue.identifier == "showItemSegue") {
        var detailController = segue.destinationViewController as ShowItemViewController
        detailController.currentId = nextId!
    }

}
Run Code Online (Sandbox Code Playgroud)

storyboard ios segue swift

35
推荐指数
1
解决办法
1万
查看次数

将活动指示器颜色更改为黑色

我正在尝试将我的活动指示器更改为黑色等自定义颜色.然而,它似乎根本不适用,并且仍然具有标准的白色.

我所做的是创建一个UIView,并添加一个活动指示器作为子视图,然后将其添加到tableFooterView.

如何更改活动指示器颜色?

viewDidLoad中:

    let footerView = UIView(frame: CGRectMake(0, 0, self.view.frame.size.width, 40))
    footerView.backgroundColor = UIColor(rgba: "#f6f7f9")
    var actInd: UIActivityIndicatorView = UIActivityIndicatorView()
    actInd.color = UIColor.blackColor()
    actInd.frame = CGRectMake(self.view.frame.size.width/2-10, 0.0, 20.0, 20.0);

    actInd.activityIndicatorViewStyle =
        UIActivityIndicatorViewStyle.WhiteLarge
    footerView.addSubview(actInd)
    actInd.startAnimating()
    self.tableVIew.tableFooterView = footerView
Run Code Online (Sandbox Code Playgroud)

objective-c ios swift

32
推荐指数
3
解决办法
3万
查看次数

在swift中更改titleTextAttribute

自从我更新xcode后,我似乎无法改变titleTextAttribute.现在,当我使用以下代码时,我收到此错误:

找不到接受这个提供的参数的重载init

代码appDelegate:

UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont(name: "Ubuntu", size: 17), NSForegroundColorAttributeName:UIColor.whiteColor()]
UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: "Ubuntu-Light", size: 15), NSForegroundColorAttributeName:UIColor.whiteColor()], forState: UIControlState.Normal)
Run Code Online (Sandbox Code Playgroud)

iphone ios appdelegate swift

24
推荐指数
2
解决办法
3万
查看次数

更新Object时防止Realm覆盖属性

我在iOS中为realm对象设置了一个REST API.但是我发现在我的对象中创建一个喜欢的标志有一个问题.我已经创建了一个最喜欢的bool,但每次从API更新对象时,它都会将收藏夹设置为默认值false.在这里,我希望此标志不会更新,因为只有本地存储了收藏夹.我怎样才能做到这一点?

class Pet: Object{
    dynamic var id: Int = 1
    dynamic var title: String = ""
    dynamic var type: String = ""
    dynamic var favorite: Bool = false


    override class func primaryKey() -> String {
        return "id"
    }
}
Run Code Online (Sandbox Code Playgroud)

CreateOrUpdate

let pet = Pet()
pet.id = 2
pet.name = "Dog"
pet.type = "German Shephard"


try! realm.write {
    realm.add(pet, update: true)
}
Run Code Online (Sandbox Code Playgroud)

realm ios swift

22
推荐指数
2
解决办法
5454
查看次数

在初始屏幕期间隐藏状态栏

我试图在启动画面期间隐藏状态栏,当我将"状态栏最初隐藏"添加到plist并将值设置为YES时,这可以正常工作,但是这会从enitre应用程序中删除statusBar,即使我已添加"查看基于控制器的状态栏外观"以plist并将值设置为NO并在appdelegate中添加以下内容:

 UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent 
Run Code Online (Sandbox Code Playgroud)

如何在不删除应用程序其余部分的情况下删除statusBar?

ios swift

20
推荐指数
4
解决办法
1万
查看次数

navigationBar中的UISearchController

我正在尝试在tableViewController中使用新的UISearchController.

但是当我像使用旧的searchDisplayController一样按下searchBar时,我对它如何在navigationController中向上移动有点困惑?

目前它只是停留在表头.

这是我的代码:

    self.teamSearchController = ({
        let controller = UISearchController(searchResultsController: nil)

        controller.searchBar.searchBarStyle = UISearchBarStyle.Minimal
        controller.dimsBackgroundDuringPresentation = false
        controller.searchBar.sizeToFit()
       controller.searchBar.showsScopeBar = true
        self.tableView.tableHeaderView = controller.searchBar

        return controller
    })()
Run Code Online (Sandbox Code Playgroud)

控制器:

在此输入图像描述

当我点击搜索栏时:

在此输入图像描述

ios swift uisearchcontroller

13
推荐指数
1
解决办法
1万
查看次数