我有一个UILabel字符串'LA'.我也有一个与其属性分配CATextLayer相同的字符.字距中的字距显着不同于.这是代码.NSAttributedStringstringUILabelCATextLayer
- (void)viewDidLoad
{
[super viewDidLoad];
//
// UILabel
//
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 50, 280, 100)];
label1.text = @"LA";
label1.backgroundColor = [UIColor clearColor];
label1.font = [UIFont fontWithName:@"Futura" size:90.0];
[self.view addSubview:label1];
//
// CATextLayer
//
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(20, 130, 280, 100)];
label2.backgroundColor = [UIColor clearColor];
CATextLayer *textLayer = [[CATextLayer alloc] init];
textLayer.frame = label2.layer.bounds;
textLayer.contentsScale = [[UIScreen mainScreen] scale];
[label2.layer addSublayer:textLayer];
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"LA"]; …Run Code Online (Sandbox Code Playgroud) 我有一个简单的示例应用程序,我创建一个CATextLayer并将其string属性设置为NSAttributedString.然后我将CATextLayer添加到视图中.
#import <CoreText/CoreText.h>
#import <QuartzCore/QuartzCore.h>
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
CTFontRef fontFace = CTFontCreateWithName((__bridge CFStringRef)(@"HelfaSemiBold"), 24.0, NULL);
NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
[attributes setObject:(__bridge id)fontFace forKey:(NSString*)kCTFontAttributeName];
[attributes setObject:[UIColor blueColor] forKey:(NSString*)kCTForegroundColorAttributeName];
NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:@"Lorem Ipsum" attributes:attributes];
CATextLayer *textLayer = [CATextLayer layer];
textLayer.backgroundColor = [UIColor whiteColor].CGColor;
textLayer.frame = CGRectMake(20, 20, 200, 100);
textLayer.contentsScale = [[UIScreen mainScreen] scale];
textLayer.string = attrStr;
[self.view.layer addSublayer:textLayer];
}
Run Code Online (Sandbox Code Playgroud)
这在模拟器中很有效,除了文本是黑色而不是蓝色.在设备上运行时,所有内容都显示在模拟器上,但它会在控制台中生成以下两个错误.
<Error>: CGContextSetFillColorWithColor: invalid context 0x0
<Error>: …Run Code Online (Sandbox Code Playgroud) 我想使用渐变作为UIView的背景.我知道这通常是用图像和backgroundColor属性完成的.但是,我想学习如何在代码中执行此操作.使用/sf/answers/135204891/我可以以UIView编程方式创建并为其提供渐变层.这非常有效.
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, 340, 280, 100)];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor redColor] CGColor], (id)[[UIColor yellowColor] CGColor], nil];
[view.layer insertSublayer:gradient atIndex:0];
[self.view addSubview:view];
Run Code Online (Sandbox Code Playgroud)
但是,如果我在Interface Builder中放置一个视图(背景设置为clear)并尝试相同的事情,渐变永远不会出现.
CAGradientLayer *gradient2 = [CAGradientLayer layer];
gradient2.frame = self.containerView.bounds;
gradient2.colors = [NSArray arrayWithObjects:(id)[[UIColor blueColor] CGColor], (id)[[UIColor greenColor] CGColor], nil];
[self.containerView.layer insertSublayer:gradient2 atIndex:0];
Run Code Online (Sandbox Code Playgroud)
我还需要在IB或代码中做些什么来使这项工作成功吗?
我Flurry.h并libFlurry.a加入到我的项目从乱舞4.1 SDK.在我的应用代表中,我有以下内容didFinishLaunchingWithOptions.
[Flurry startSession:@"[apikey]"];
Run Code Online (Sandbox Code Playgroud)
我还在[Flurry logEvent:@"callAPIPath"];代码库中添加了它,在典型的会话中将被调用5或6次.但是,我在Flurry仪表板上看不到任何数据.我正在iOS模拟器中测试并单击主页按钮退出应用程序,因为这是在/sf/answers/843839881/中建议的.我已经花了24小时处理它但仍然没有数据.
我没有在调试输出中看到任何明显的问题.
2013-01-29 16:04:04.579 TumTiki[7578:c07] Flurry: startSession called for the first time
2013-01-29 16:04:04.580 TumTiki[7578:c07] Flurry: Start session called with apiKey[APIKEY]
2013-01-29 16:04:04.580 TumTiki[7578:c07] Flurry: Trim white space and use apiKey[APIKEY]
2013-01-29 16:04:04.581 TumTiki[7578:c07] initial network status [1] =========
2013-01-29 16:04:04.583 TumTiki[7578:c07] FlurrySession: Add session with startTime[2013-01-29 23:04:37 +0000] to saved sessions
2013-01-29 16:04:04.587 TumTiki[7578:c07] FlurrySession: Add crashed former session
2013-01-29 16:04:04.589 TumTiki[7578:c07] FlurrySession: Initialized …Run Code Online (Sandbox Code Playgroud)