小编mkz*_*mkz的帖子

导航栏右栏按钮项间距

我创建了一个导航栏http://oi61.tinypic.com/r0p8w4.jpg,从故事板,titleView和代码中的三个右键按钮项添加了左栏按钮项.

这是代码:

override func viewDidLoad() {
    super.viewDidLoad()

    var screenWidth = UIScreen.mainScreen().bounds.width
    // custom title view
    var navBarWidth: CGFloat = self.navigationController!.navigationBar.frame.size.width
    let customTitleView = UIView(frame: CGRectMake(0, 0, navBarWidth, 44))
    titleLabel = UILabel(frame: CGRectMake(20, 0, navBarWidth, 40))
    titleLabel.text = conversationName
    if let titleFont = UIFont(name: "Roboto-Regular", size: 20) {
        titleLabel.font = titleFont
    }
    titleLabel.textColor = UIColor.whiteColor()

    customTitleView.addSubview(titleLabel)
    self.navigationItem.titleView = customTitleView

    // right bar buttons
    var searchImage = UIImage(named: "search")!
    var clipImage = UIImage(named: "clip")!
    var pencilImage = UIImage(named: "pencil")!

    var …
Run Code Online (Sandbox Code Playgroud)

uibarbuttonitem uinavigationitem ios swift

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

UINavigationBar在AppDelegate.swift中设置自定义阴影

我想在整个应用程序的UINavigationBar底部设置一些阴影.这是我尝试过但它不起作用:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    UINavigationBar.appearance().layer.shadowOffset = CGSizeMake(0, 3)
    UINavigationBar.appearance().layer.shadowRadius = 3.0
    UINavigationBar.appearance().layer.shadowColor = UIColor.yellowColor().CGColor
    UINavigationBar.appearance().layer.shadowOpacity = 0.7
}
Run Code Online (Sandbox Code Playgroud)

请告诉我该怎么做?

更新: 通过UINavigationController的子类化解决

import UIKit

class ShadowUINavigationController: UINavigationController {

    override func viewWillAppear(animated: Bool) {
        let darkColor: CGColorRef = UIColor(hex: 0x212121).CGColor
        let lightColor: CGColorRef = UIColor.clearColor().CGColor
        let navigationBarBottom: CGFloat = self.navigationBar.frame.origin.y + self.navigationBar.frame.size.height + 20
        println(self.navigationBar.frame.origin.y)
        println(self.navigationBar.frame.size.height)
        println(navigationBarBottom)

        let newShadow: CAGradientLayer = CAGradientLayer()
        newShadow.frame = CGRectMake(0, navigationBarBottom, self.view.frame.size.width, 1)
        newShadow.colors = [darkColor, lightColor]
        self.view.layer.addSublayer(newShadow)
        super.viewWillAppear(animated)
    } …
Run Code Online (Sandbox Code Playgroud)

shadow uinavigationbar ios appdelegate swift

6
推荐指数
1
解决办法
3008
查看次数

UITabBar 背景图像的图像缩放

我在我的应用程序中创建了 UITabBarController。

然后在viewDidLoad()我想更改 UITabBar 背景图像。这是我试图让它工作的代码:

class MainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        UITabBar.appearance().translucent = false
        UITabBar.appearance().backgroundColor = UIColor.clearColor()
        UITabBar.appearance().backgroundImage = UIImage(named: "tabbar_background")
        UITabBar.appearance().contentMode = .ScaleAspectFit
    }
}
Run Code Online (Sandbox Code Playgroud)

但结果不正确(image)。有人可以帮我让它填满整个标签栏框架吗?

background uitabbar ios swift

5
推荐指数
1
解决办法
8788
查看次数

NSCalendar按月提供错误的周数

我有一个函数,它返回一个由月和年组成的周数数组.

这是代码:

let calendar = NSCalendar.currentCalendar()
let weekRange = calendar.rangeOfUnit(NSCalendarUnit.CalendarUnitWeekOfYear, inUnit: .CalendarUnitMonth, forDate: NSDate())
weekArray = Array(weekRange.location..<weekRange.location + weekRange.length)
Run Code Online (Sandbox Code Playgroud)

示例:对于2015-08-21,它将返回[31,32,33,34,35,36],这是正确的,因为该网站.

它工作正常,但我发现一个错误,如果我通过这个日期"2016-01-01"它返回[1,2,3,4,5],但正确的数组应该是[53(从2015年),1, 2,3,4](再次在本网站查看).

如该网站所述:

一年中的第一周(WN 1)是包含1月4日或本年度第一个星期二的一周.

那么,我必须写一些计算才能使它有效吗?或者有一个更简单的解决方案?感谢帮助.

week-number nscalendar ios swift

2
推荐指数
1
解决办法
915
查看次数

使用PubNub开发聊天应用程序

我必须创建一种让用户互相聊天的能力.我发现PubNub是解决这个问题的好工具.但它似乎并不像我预期的那么容易(.

用户登录后,他在对话屏幕上.对话存储在我的服务器上的数据库中.db中的对话行示例:conversationID,conversationName,string - 用空格分隔的用户ID.要获取会话列表,我可以向服务器数据库发送请求,获取并显示在屏幕上.此外,我必须订阅所有这些对话渠道.我认为每个会话的频道名称可以是数据库中的ID号.

此外,我创建了一个用户可以创建对话的屏幕.他可以选择一个或多个随播广告,并向所选用户发送邀请.

然后,当用户向另一个人发送邀请时,我必须在我的数据库中添加新的会话记录,并以某种方式通知该用户邀请.我怎么能做到这一点?我应该使用PubNub的推送通知吗?如此处所述,我必须注册我的应用程序才能获得推送通知,然后我可以向通道发送通知.但是,如果用户尚未订阅此频道,用户将如何获得此通知?我被困在这里.

apple-push-notifications ios pubnub swift

2
推荐指数
1
解决办法
504
查看次数