小编Kru*_*nal的帖子

NSData到UIImage

我正在尝试保存UIIMage,然后检索并显示它.我已成功将图像保存在捆绑中,从那里检索并显示.我的问题来自于我尝试将图像保存到磁盘(将其转换为NSData),然后检索它.我像这样将图像转换为NSData ...

NSData* topImageData = UIImageJPEGRepresentation(topImage, 1.0);
Run Code Online (Sandbox Code Playgroud)

然后我把它写成磁盘就像这样......

[topImageData writeToFile:topPathToFile atomically:NO];
Run Code Online (Sandbox Code Playgroud)

然后我试着像这样检索它......

topSubView.image = [[UIImage alloc] initWithContentsOfFile:topPathToFile];
Run Code Online (Sandbox Code Playgroud)

它不返回任何图像(大小为零).所以我试过......

NSData *data = [[NSData alloc] initWithContentsOfFile:topPathToFile];
topSubView.image = [[UIImage alloc] initWithData:data];
Run Code Online (Sandbox Code Playgroud)

无济于事.当我单步执行调试器时,我确实看到数据包含正确的字节数,但我很困惑为什么我的图像没有被创建.我错过了一步吗?在转换为图像之前,我是否需要对NSData执行某些操作?

iphone uiimage nsdata

20
推荐指数
3
解决办法
6万
查看次数

无法转换'[String:AnyObject]类型的值?' 预期的参数类型'[NSAttributedStringKey:Any]?'

如何将类型的值转换'[String : AnyObject]?'为预期的参数类型'[NSAttributedStringKey : Any]?'

open class func drawText(context: CGContext, text: String, point: CGPoint, 
align: NSTextAlignment, attributes: [String : AnyObject]?)
{
    var point = point

    if align == .center
    {
        point.x -= text.size(withAttributes: attributes).width / 2.0
    }
    else if align == .right
    {
        point.x -= text.size(withAttributes: attributes).width
    }

    NSUIGraphicsPushContext(context)

    (text as NSString).draw(at: point, withAttributes: attributes)

    NSUIGraphicsPopContext()
}
Run Code Online (Sandbox Code Playgroud)

nsattributedstring swift swift4 nsattributedstringkey

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

更改Xcode 4.3.2的iPad/iPhone模拟器分辨率

我正在研发飞利浦19"并将Xcode升级到版本4.3.2.在iPad 3上的新"Retina Display"上(哦,对不起,在新iPad上)我的iPad模拟器改变了它的分辨率,模拟器有垂直和水平滚动条!

如何更改iOS模拟器的分辨率?

xcode simulator screen-resolution ios ios-simulator

19
推荐指数
1
解决办法
4472
查看次数

更改iOS模拟器保存的屏幕截图的位置

我想更改通过文件>保存屏幕截图在iOS模拟器中创建的屏幕截图的位置从桌面保存到我选择的文件夹.如何才能做到这一点?也许我可以更改用户默认值,就像在OS X上指定标准屏幕截图的位置一样?

screenshot simulator ios ios-simulator

19
推荐指数
3
解决办法
6205
查看次数

在UICollectionViewFlowLayoutBreakForInvalidSizes处创建一个符号断点

我在我的代码中得到了这个错误,它说" UICollectionViewFlowLayoutBreakForInvalidSizes在调试器中创建一个符号断点".我很困惑,实际上这里问的是我正在考虑的代码,要求它放在哪里,不知道在哪里?

import UIKit

// MARK: - CUSTOM SOCIAL CELL
class SocialCell:UICollectionViewCell {

    /* Views */
    @IBOutlet weak var socialIcon: UIImageView!
    @IBOutlet weak var socialLabel: UILabel!
}

class SocialList: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {

    /* Views */
    @IBOutlet weak var socialCollView: UICollectionView!

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    // MARK: - COLLECTION VIEW DELEGATES 
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }

    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return socials.count //socialNames.count
    }

    func collectionView(collectionView: UICollectionView, …
Run Code Online (Sandbox Code Playgroud)

xcode ios uicollectionview swift2

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

在Xcode中启用代码折叠栏

如何启用行号旁边的代码折叠栏?

我用谷歌搜索"代码折叠Mac"; 这一切都是关于触发代码折叠和展开,但没有关于启用条形码.

我曾尝试使用Editor -> Code Folding -> Fold/Unfold折叠和展开代码,但我没有在行号旁边的垂直条; 所以,我有按钮点击折叠和展开.

我该如何启用该栏?

请在此处查看图片.

xcode code-folding ios

18
推荐指数
3
解决办法
2869
查看次数

Pod文件未初始化?

当我尝试初始化pod文件以cocoapods通过终端使用时,它给了我这个错误.如何解决它.

/Library/Ruby/Gems/2.0.0/gems/cocoapods-1.2.0/lib/cocoapods/command.rb:128:in `verify_minimum_git_version!': [!] You need at least git version 1.8.5 to use CocoaPods (Pod::Informative)
Run Code Online (Sandbox Code Playgroud)

xcode command-line-tool ios cocoapods xcode10

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

xcode 9中xib的安全区域是什么?

你能否告诉我xcode 9中xibs中的安全区域(图中突出显示)是什么?这有什么用?

在此输入图像描述

xib ios xcode9 safearealayoutguide

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

在UILabel中的单词分隔符上添加连字符

如何设置UILabel lineBreakMode来破坏单词并为断字添加连字符?

一个破碎的标签 -

rd应该是这样的

hyphen word-wrap uilabel ios nsparagraphstyle

17
推荐指数
3
解决办法
9772
查看次数

Swift 3 Array,使用.remove(at:i)一次删除多个项目

是否可以从数组中删除多个项目,同时使用索引位置按照.remove(at:i)类似:

伪代码:

myArray.remove(at: 3, 5, 8, 12)
Run Code Online (Sandbox Code Playgroud)

如果是这样,这样做的语法是什么?


更新:

我正在尝试这个,它有效,但下面答案中的扩展更具可读性和合理性,并且实现了与伪代码完全相同的目标.

创建一系列"位置":[3,5,8,12]

let sorted = positions.sorted(by: { $1 < $0 })
for index in sorted
{
    myArray.remove(at: index)
}
Run Code Online (Sandbox Code Playgroud)

arrays xcode ios swift indexpath

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