小编Kha*_*inn的帖子

从类方法或类型方法SWIFT UIColor

在objective-c中,我们可以像这样编写用类方法调用颜色.

+ (UIColor *)getFromRGB:(int)red green:(int)green blue:(int)blue
{
    float r = (float)red / 255;
    float g = (float)green / 255;
    float b = (float)blue / 255;
    return [UIColor colorWithRed:r green:g blue:b alpha:1];
}
Run Code Online (Sandbox Code Playgroud)

然后,我们可以像这样打电话.

cell.backgroundColor = [Helpers getFromRGB:216 green:38 blue:56]
Run Code Online (Sandbox Code Playgroud)

在Swift中,我从中读取并称之为Type方法. https://developer.apple.com/library/prerelease/mac/documentation/Swift/Conceptual/Swift_Programming_Language/Methods.html

所以,我试着这样写.

class Helper
{
    class func colorFromRGB (red: Int, green: Int, blue: Int) -> UIColor
    {
        var color: UIColor = UIColor(red: CGFloat(red/255), green: CGFloat(green/255), blue: CGFloat(blue/255), alpha: CGFloat(1.0))
        return color
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我调用Type方法时,我得到了这样的错误.我应该怎么做? 在此输入图像描述

修改:也不能像那样打电话.之后,根据xCode自动建议,我没有像这样的红色参数这样写.然后,我可以编译,但我只能得到那样的黑色.我认为调用方法和颜色信息也错了.我该怎么办?

在此输入图像描述

在此输入图像描述

methods objective-c uicolor swift

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

检查完全访问权限以获取自定义键盘扩展名

我需要检查自定义键盘扩展的完全访问权限。我找到了此链接。

如何检查iOS 8中是否启用了“允许完全访问”?

它说我们可以检查App组。我有一个名为“ group.TTT.TGroup”的应用程序组。它在主应用程序和自定义键盘之间共享访问权限。

然后,我这样检查。问题是我总是可以访问它(总是有array或error = null)。是因为我共享相同的数据吗?但是,如果我的应用程序使用另一个应用程序组,而扩展程序使用另一个应用程序组,则我绝对不能访问它。我可以知道怎么做吗?

NSFileManager* fileManager = [NSFileManager defaultManager];
NSString *path = [fileManager containerURLForSecurityApplicationGroupIdentifier:@"group.TTT.TGroup"].path;
NSError *error;
NSArray *arr = [fileManager contentsOfDirectoryAtPath:path error:&error];

NSLog(@" arr is %@",arr);
if (arr == nil || !arr) //can check error also
    accessOn = NO;

else accessOn = YES;
Run Code Online (Sandbox Code Playgroud)

objective-c ios8 ios-app-extension ios-app-group custom-keyboard

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

TTTAttributedLabel sizetofit和sizeWithFont是不同的

我正在使用TTTAttributedLabel,我通常在tableview单元格中使用sizetofit.之后,我在单元格高度计算中使用sizeWithFont.我像这样设置了TTTAttributedLabel.

[self.attributedLabel setText:@"Test\n\n\n\n"];
CGSize contentSize = [self.attributedLabel.text sizeWithFont:self.attributedLabel.font
                                      constrainedToSize:CGSizeMake(CGRectGetWidth(self.attributedLabel.frame), 1000)
                                          lineBreakMode:NSLineBreakByWordWrapping];

[self.attributedLabel sizeToFit];
Run Code Online (Sandbox Code Playgroud)

我注意到身高不同了.我得到了这样的输出.所以我猜这是错的.我可以知道如何解决?我在iOS 8设备上测试.

在此输入图像描述

uilabel sizewithfont ios sizetofit tttattributedlabel

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

使用限制查询 Firebase 数据库

我刚开始使用 firebase,它非常有用。

我有这样的节点。

在此处输入图片说明

目前,我是这样写的,它会返回我所有的消息。如果我有 1k 条消息,它将返回 1k 条消息。我只想查询最新的 100 条消息。是否可以?我需要编写云函数吗?

private void retrieveConversation(String conversationID) {

    Query queryRoom = FirebaseDatabase.getInstance().getReference().child("Conversation").child(conversationID);
    queryRoom.keepSynced(true);
    queryRoom.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Conversation conversation = dataSnapshot.getValue(Conversation.class);
            if (conversation != null) {
                conversation = updateConversation(conversation);
                mainMessage.conversations.put(conversation.getId(), conversation);
                EventBus.getDefault().post(new ChatAdapter.AddMessage());
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

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

android firebase firebase-realtime-database

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

在Parse for iOS中更新bool值

我正在使用Parse for iOS.https://www.parse.com/docs/downloads/ 但是,我在更新指定objectID的bool值时遇到了困难,如图所示.

http://tinypic.com/view.php?pic=8y4zt2&s=5

我可以通过设置这样添加新行.但是,现在,我想更新指定objectID的bool值.我想知道怎么做.

PFObject *gameScore = [PFObject objectWithClassName:@"GameScore"];
[gameScore setObject:[NSNumber numberWithBool:NO] forKey:@"cheatMode"];
Run Code Online (Sandbox Code Playgroud)

boolean updates ios

0
推荐指数
1
解决办法
4007
查看次数

UIStoryboard中的iOS 8自定义选项卡栏控制器

我试图在iOS 8的UIStoryboard中使用swift创建自定义标签栏控制器(objective-c也没关系).所以,我计划使用这段代码.

let item0: UITabBarItem = UITabBarController().tabBar.items[0] as UITabBarItem
item0.setFinishedSelectedImage(selectedImage0, withFinishedUnselectedImage: unselectedImage0)
Run Code Online (Sandbox Code Playgroud)

但是,问题是setFinishedSelectedImage不再支持,我看到了这个错误.我该如何实施?

从iOS 7及更早版本开始不推荐使用的API在Swift中不可用

uitabbarcontroller uistoryboard swift ios8

0
推荐指数
1
解决办法
4235
查看次数

ios隐藏左侧导航按钮的文本

我只需要显示箭头按钮并隐藏左侧导航按钮的文本.根据这个链接,我可以这样做.但如果我喜欢这样,滑动返回功能将被破坏.

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
Run Code Online (Sandbox Code Playgroud)

所以,我用这个来隐藏文字.

self.navigationController.navigationBar.topItem.title = @"";
Run Code Online (Sandbox Code Playgroud)

到目前为止,没关系.但是,如果我之前的视图的searchDisplayController处于活动状态并且推送到新视图,则会显示左侧导航按钮文本.我可以知道该怎么办吗?

uinavigationcontroller uinavigationitem ios

0
推荐指数
1
解决办法
1439
查看次数