在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自动建议,我没有像这样的红色参数这样写.然后,我可以编译,但我只能得到那样的黑色.我认为调用方法和颜色信息也错了.我该怎么办?


我需要检查自定义键盘扩展的完全访问权限。我找到了此链接。
它说我们可以检查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
我正在使用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设备上测试.

我刚开始使用 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) 我正在使用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) 我试图在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中不可用
我只需要显示箭头按钮并隐藏左侧导航按钮的文本.根据这个链接,我可以这样做.但如果我喜欢这样,滑动返回功能将被破坏.
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处于活动状态并且推送到新视图,则会显示左侧导航按钮文本.我可以知道该怎么办吗?
ios ×3
ios8 ×2
objective-c ×2
swift ×2
android ×1
boolean ×1
firebase ×1
methods ×1
sizetofit ×1
sizewithfont ×1
uicolor ×1
uilabel ×1
uistoryboard ×1
updates ×1