小编Rya*_*los的帖子

如何在以编程方式创建的UIButton上添加padding-left?

我在添加左侧填充时遇到问题UIButton.我有一个UIButtonUIControlContentHorizontalAlignmentLeft.我希望文本显示在左侧,但它太左了.当我给边框时,它看起来不太好.我想在CSS中给出一些关于5px的文本填充.我用谷歌搜索解决方案,但找不到一个特别适合UIButton.在此先感谢您的帮助.

xcode padding uibutton swift imageedgeinsets

63
推荐指数
5
解决办法
8万
查看次数

如何使NSString路径(文件名)安全

我正在使用非常棘手的战斗方法:)来制作一个像Fi?le*/ Name文件名一样安全的字符串File_Name.我敢肯定有一种可可的方式来转换它.我相信最好的地方就是:)

谢谢!

string cocoa filenames nsstring

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

在Swift,AnyObject类型中解析json

我正在尝试解析json,但我对数据类型有一些困难,特别是AnyObject类型+向下转换.

让我们考虑下面的json(它是一个完整的json的摘录).

{  "weather":
   [
      {
         "id":804,
         "main":"Clouds",
         "description":"overcast clouds",
         "icon":"04d"
      }
   ],
}
Run Code Online (Sandbox Code Playgroud)

对我来说,json可以描述如下:

- json: Dictionary of type [String: AnyObject] (or NSDictionary, so = [NSObject, AnyObject] in Xcode 6 b3)
    - "weather": Array of type [AnyObject] (or NSArray)
         - Dictionary of type [String: AnyObject] (or NSDictionary, so = [NSObject, AnyObject] in Xcode 6 b3)
Run Code Online (Sandbox Code Playgroud)

我的json是AnyObject类型!(我用来JSONObjectWithData从URL获取JSON).

然后我想访问天气词典.这是我写的代码.

var localError: NSError?
var json: AnyObject! = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &localError)

if let dict = json as? [String: AnyObject] …
Run Code Online (Sandbox Code Playgroud)

parsing json swift

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

iPhone:如何使用buttonType UIButtonTypeCustom设置UIButton的BackgroundColor

我想在点击时更改按钮颜色.我用了 :

[button setBackgroundColor:[UIColor redColor]];
Run Code Online (Sandbox Code Playgroud)

但这只显示按钮的四个角上的红色而不是整个按钮,当我使用时forState:UIControlStateNormal,应用程序挂起.点击时按钮是否可以显示某些颜色?

[click1 setBackgroundColor:[UIColor redColor] forState:UIControlStateHighlighted];
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

iphone xcode objective-c ipad

33
推荐指数
5
解决办法
6万
查看次数

带有多个按钮的导航栏

我有一个带左右按钮的导航栏,我需要在右键旁边放另一个按钮.有谁知道我怎么能这样做?以下是一些有用的代码:

- (id)init {
    self = [super initWithStyle:UITableViewStyleGrouped];
    if (self) {

        _pinArray = [[NSArray alloc]init];
        _pinArray = [Data singleton].annotations;

        UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithTitle:@"Map"
                                                                 style:UIBarButtonItemStylePlain
                                                            target:self
                                                            action:@selector(goToMap:)];
        self.navigationItem.rightBarButtonItem = right;

        UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithTitle:@"Menu"
                                                            style:UIBarButtonItemStylePlain
                                                           target:self
                                                           action:@selector(goToMenu:)];
        self.navigationItem.leftBarButtonItem = left;
        self.navigationItem.title = @"My Homes";
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

objective-c uinavigationcontroller uibarbuttonitem ios

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

获取客户端中iOS Universal Framework的版本号

这可能不仅限于iOS Universal Frameworks,而是所有xxx.framework文件.但是,我似乎无法找到有关如何在客户端应用程序中获取当前版本和构建框架的文档.在应用程序中,您可以使用以下内容:

    NSString *name = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
    NSString *build = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
Run Code Online (Sandbox Code Playgroud)

这将为您提供存储在应用程序的Info.plist中的当前信息.但是我们如何找到框架的信息.就我而言,特别是嵌入式框架.

cocoa-touch frameworks ios ios-universal-framework

16
推荐指数
3
解决办法
9309
查看次数

无法在属性初始值设定项中使用实例成员

我写了一个习惯UIView,我发现了一个奇怪的问题.我认为这与一个非常基本的概念有关,但我只是不理解它,感叹.....

class ArrowView: UIView {

    override func draw(_ rect: CGRect) {

        let arrowPath = UIBezierPath.bezierPathWithArrowFromPoint(startPoint: CGPoint(x:bounds.size.width/2,y:bounds.size.height/3), endPoint: CGPoint(x:bounds.size.width/2, y:bounds.size.height/3*2), tailWidth: 8, headWidth: 24, headLength: 18)

        let fillColor = UIColor(red: 0.00, green: 0.59, blue: 1.0, alpha: 1.0)
        fillColor.setFill()
        arrowPath.fill()
    }
}
Run Code Online (Sandbox Code Playgroud)

这段代码工作正常,但如果我从覆盖绘制函数中抓取这一行,它就不会编译.错误说我不能使用bounds属性.

let arrowPath = UIBezierPath.bezierPathWithArrowFromPoint(startPoint: CGPoint(x:bounds.size.width/2,y:bounds.size.height/3), endPoint: CGPoint(x:bounds.size.width/2, y:bounds.size.height/3*2), tailWidth: 8, headWidth: 24, headLength: 18)
Run Code Online (Sandbox Code Playgroud)

不能在属性初始值设定项中使用实例成员'bounds'; 属性初始化程序在'self'可用之前运行

我不明白为什么我不能在func draw中使用这个界限

ios swift3

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

将"SF UI Display Bold"设置为标签字体

我将标签的字体设置为SF UI Display Bold时出现问题.

我不想设置这种持久性,只有当布尔值为假时.

if (value.messageReaded == false) {
    cell.subjectLabel?.font = UIFont(name:"SF UI Display Bold", size: 17.0)
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,我的方法不适用于这种字体.

有人在swift中知道"SF UI Display Bold"字体的正确标题吗?

谢谢!

fonts ios swift ios9

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

在尝试将数组追加到Swift中的其他数组时获取"无关的参数标签"

我越来越extraneous argument label 'contentsOf:' in call array.append(contentsOf: test)想在操场上运行该代码时出错:

import Cocoa

var array:[Any] = []
let test = [""]
array.append(contentsOf: [""])
array.append(contentsOf: test)
Run Code Online (Sandbox Code Playgroud)

为什么会这样?据我所知,有两个相等的数组,空字符串.

arrays compiler-errors append swift

14
推荐指数
1
解决办法
6213
查看次数

rgb(34,34,34)到UIColor

我在表单中有一个RGB字符串rgb(34, 34, 34).我想将它解析为UIColor使用iOS.我相信我需要一个正则表达式,但我似乎无法破解它.这就是我到目前为止所拥有的.

NSString *regExString = @"(.*?)rgb\((\d+), (\d+), (\d+)\)";

NSError *error = nil;

NSRegularExpression *regEx = [NSRegularExpression regularExpressionWithPattern:regExString
                                                                       options:NSRegularExpressionCaseInsensitive error:&error];

NSArray *matches = [regEx matchesInString:backgroundColorString options:NSRegularExpressionCaseInsensitive
                                        range:NSMakeRange(0, backgroundColorString.length)];
Run Code Online (Sandbox Code Playgroud)

如果有人能把我送到正确的方向,那就太好了.

regex uicolor ios

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