更新 2:我仍然希望能得到一些帮助来解决这个问题,所以我现在要稍微改进我的问题,因为我已经更好地缩小了它的范围。
我的UIViewController层次结构如下所示:
如果用户触摸过滤器图标并选择电梯类型,则会出现过滤器视图。左边的图像是没有选择过滤器的样子,右边的图像是选择过滤器的样子。导航区域(以绿色标出)是我想要设计的样式。
这是我无法弄清楚的事情。如果我添加这两件事:
UINavigationBar.appearance().translucent = false
UINavigationBar.appearance().barTintColor = UIColor(hexString: "232B35")
Run Code Online (Sandbox Code Playgroud)
然后导航区域和过滤器视图之间会出现一个空白区域:
如果我将 translucent 属性设置为 true,则不会出现该空白区域,但是 barTintColor 没有效果。
请注意,我没有把UINavigationBar我的UIViewController。我只有一个UINavigationItem我正在添加的代码。
在这一点上,我的问题是 - 为什么当UINavigationBar.appearance().translucent = false我的代码中有大的空白时会突然出现(我可以做些什么来摆脱它,但仍会更改导航区域的颜色)?
我真的被困住了,希望得到一些帮助。谢谢!
以下是我的原始问题,其中的信息可能有帮助,也可能无济于事:
我正在尝试设计我的应用程序的样式,但这样做很困难。在一个UIViewController我有一个 ThemeManager ,它struct有一个将主题应用于应用程序的函数,并且在该方法代码中使导航栏与应用程序的背景颜色混合:
static func applyTheme(theme: Theme) {
// set the background color
sharedApplication.delegate?.window??.backgroundColor = UIColor(hexString: "232B35")
UINavigationBar.appearance().translucent = false // these are the offenders
UINavigationBar.appearance().barTintColor = UIColor(hexString: "232B35")
// first, set backgroundimage to nothing
UINavigationBar.appearance().setBackgroundImage( …Run Code Online (Sandbox Code Playgroud) 我在 userDefaults 中保存 NSManagedObject 有困难,我想知道 a) 我应该尝试这样做还是这不是一种合适的方法,或者 b) 如果它是一种合适的方法,我怎样才能让它工作?
我正在用 Swift 2.3 编写我的应用程序,它有一些用户默认选项,其中一个用于默认“提升”(如举重,例如“卧推”、“挺举”、“倾斜卧推” )。我实际上将它们从枚举转换为核心数据实体,因为用户能够跟踪的每个电梯事件都将是可用的电梯类型之一(我将为其建立适当的关系)。
这是具有属性的扩展:
extension Lift {
@NSManaged var liftName: String
@NSManaged var type: NSSet
}
Run Code Online (Sandbox Code Playgroud)
以及带有 Xcode 抱怨的 Lift 实体:
class Lift: NSManagedObject, NSCoding {
func encodeWithCoder(aCoder: NSCoder) {
aCoder.encodeObject(liftName, forKey: "liftName")
} // Super.init isn't called on all paths before returning from initializer
required init(coder aDecoder: NSCoder) {
// Initialization of immutable variable was never used, etc...
let liftName = aDecoder.decodeObjectForKey("liftName") as! String
}
}
Run Code Online (Sandbox Code Playgroud)
我以前处理过这些类型的错误,所以我真正关心的是我是否走上了错误的道路。
今晚我读了很多线程,这些线程告诉我我需要对一个对象(但不是特别是 …
我已经弄清楚如何修改标记中出现的文本和 x、y 值,但我不知道如何在标记中显示其他数据。
这是我目前的标记:
我想显示用于计算 y 值的两个值,而不是 x 和 y 值:
“5 次 @ 200 磅”
更新:换句话说,图表上显示的点是 233.3(y 值)。但我需要让标签显示 5 和 200,它们用于计算图表上的点 233.3 的结果。
看起来我会使用func refreshContent(entry: ChartDataEntry, highlight: Highlight),但这需要 aChartDataEntry并且我想显示的值不是数据点(ChartDataEntry)。
我已经浏览了 Github 项目上的所有问题,我能找到的最接近解决方案的是这个线程,但答案并不能真正帮助初学者级别的开发人员。
有人可以教我如何在标记中显示非数据点数据吗?
更新:感谢 @RazibMollick 指导我找到解决方案,即在我的方法中使用ChartDataEntry带有附加参数 ( ) 的初始化程序:ChartDataEntry(x:y:data:)generatedLineData
let numberFormatter = NumberFormatter()
let repetitions = numberFormatter.string(from: liftEvents[index].repetitions)
let weightLifted = numberFormatter.string(from: liftEvents[index].weightLifted)
let liftData = LiftData(repetitions: repetitions!, weightLifted: weightLifted!)
return ChartDataEntry(x: (thisDateInSeconds! - beginningDateInSeconds) …Run Code Online (Sandbox Code Playgroud) 我的函数用于在公斤和磅之间进行转换。由于某些未知原因,该converted(to:)方法似乎要么返回 0(我认为不太可能),要么将返回的值分配给liftWeight不起作用。
func convertUnit(liftEvent: LiftEventRepresentable ) -> LiftEventRepresentable {
let unit = liftEvent.liftWeight.unit.symbol
switch unit {
case "kg":
let weight = liftEvent.liftWeight
print("Event weight is \(weight)") // 110.0 kg
let liftWeight = weight.converted(to: .pounds) // this is returning 0 or the assignment isn't working
print("The new weight is \(liftWeight)") 0.0 lb
liftEvent.updateWeightLifted(liftWeight.value)
liftEvent.updateWeightUnit(liftEvent.liftWeight.unit.symbol)
return liftEvent
case "lb":
// I'll finish this case after I get case "kg": working
default:
fatalError("Oops, this should not happen")
}
} …Run Code Online (Sandbox Code Playgroud)