小编Mon*_*WTF的帖子

如何使用swift仅锁定主视图的纵向方向

我使用swift为iPhone创建了一个应用程序,它由嵌入在导航控制器中的许多视图组成.我想将主视图锁定为纵向方向,并且仅锁定横向方向的导航控制器的子视图.这是我的意思的一个例子:

  • UINavigationController的
    • UiViewController1(纵向锁定)初始视图控制器,导航栏上有一个按钮,可以让用户访问可以选择其他视图的列表
    • UIViewController2(景观锁定)
    • UiViewController3(人像与风景)
    • UiViewController4(人像与风景)
    • ...
    • ...

我怎样才能做到这一点?

ios swift

39
推荐指数
7
解决办法
5万
查看次数

NSFontAttributeName已更改为String

我正在尝试正确设置导航栏的样式,我需要将字体更改为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)

但编译器继续给我一个与字体中的磅值相关的错误,我该如何解决?

string uinavigationbar swift

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

使用swift检查数字是否为十进制

如何使用swift检查数字是否为小数?

使用Objective-C:

if (number == (int) number) {
  //decimal
}
else {
  //not decimal
}
Run Code Online (Sandbox Code Playgroud)

ios swift

11
推荐指数
3
解决办法
7950
查看次数

Swift - 查找列表中的重复元素

我有以下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)

我能怎么做?

ios swift

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

Swift - 从字符串中删除空格不起作用

我正在尝试从字符串中删除空格和一些字符,请检查下面的代码

// 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)

xcode ios swift

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

Swift - 限制 UITextview 行中的字符数

我有以下代码来限制 UITextView 中的行数

textView.textContainer.maximumNumberOfLines = 10
textView.textContainer.lineBreakMode = .byTruncatingTail
Run Code Online (Sandbox Code Playgroud)

但是有没有办法限制每行的字符数?如何将每行的限制设置为 50 个字符?

编辑: 我尝试了尽可能重复的解决方案,但限制应用于整个文本,我需要为每一行设置限制。

uitextview ios swift

3
推荐指数
1
解决办法
4560
查看次数

标签 统计

swift ×6

ios ×5

string ×1

uinavigationbar ×1

uitextview ×1

xcode ×1