我使用swift为iPhone创建了一个应用程序,它由嵌入在导航控制器中的许多视图组成.我想将主视图锁定为纵向方向,并且仅锁定横向方向的导航控制器的子视图.这是我的意思的一个例子:
我怎样才能做到这一点?
我正在尝试正确设置导航栏的样式,我需要将字体更改为helvetica neue,大小为19.我曾经使用过此代码,但我注意到现在不能正常工作:
navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "HelveticaNeue-Light", size: 19)]
Run Code Online (Sandbox Code Playgroud)
发生这种情况是因为NSFontAttributeName的类型已更改为String,我试图修复它
navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: "HelveticaNeue-Light, 19"]
Run Code Online (Sandbox Code Playgroud)
但编译器继续给我一个与字体中的磅值相关的错误,我该如何解决?
如何使用swift检查数字是否为小数?
使用Objective-C:
if (number == (int) number) {
//decimal
}
else {
//not decimal
}
Run Code Online (Sandbox Code Playgroud) 我有以下UITextField列表:
let list = [(name1TextField, phone1TextField), (name2TextField, phone2TextField), (name3TextField, phone3TextField), (name4TextField, phone4TextField), (name5TextField, phone5TextField)]
Run Code Online (Sandbox Code Playgroud)
我正试图找到手机重复并打印出来
编辑
例如(元组可能是空的)
list = [("john", "555-444-333"), ("james", "555-444-333"), ("",""), ("bob", "333-222-111"), ("nancy", "222-111-444"), ]
output 555-444-333
Run Code Online (Sandbox Code Playgroud)
我能怎么做?
我正在尝试从字符串中删除空格和一些字符,请检查下面的代码
// giving phoneString = +39 333 3333333
var phoneString = ABMultiValueCopyValueAtIndex(phone, indexPhone).takeRetainedValue() as! String
// Remove spaces from string
phoneString = phoneString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
// Remove +39 if exist
if phoneString.rangeOfString("+39") != nil{
phoneString = phoneString.stringByReplacingOccurrencesOfString("\0", withString: "+39", options: NSStringCompareOptions.LiteralSearch, range: nil)
}
print(phoneString) // output +39 333 3333333
Run Code Online (Sandbox Code Playgroud)
好像所有的变化对我的字符串都没有影响,为什么会这样呢?
编辑@VS
编辑2:
我试图在utf 8中转换我的字符串,检查结果:
43 51 57 194 160 51 51 51 194 160 51 51 51 51 51 51 51
Run Code Online (Sandbox Code Playgroud)
哪里:
43 = +
51 = 3
57 = 9 …Run Code Online (Sandbox Code Playgroud) 我有以下代码来限制 UITextView 中的行数
textView.textContainer.maximumNumberOfLines = 10
textView.textContainer.lineBreakMode = .byTruncatingTail
Run Code Online (Sandbox Code Playgroud)
但是有没有办法限制每行的字符数?如何将每行的限制设置为 50 个字符?
编辑: 我尝试了尽可能重复的解决方案,但限制应用于整个文本,我需要为每一行设置限制。