小编Der*_*ick的帖子

如何在drawRect中填充渐变路径:?

用纯色填充路径很容易:

CGPoint aPoint;
for (id pointValue in points)
{
    aPoint = [pointValue CGPointValue];
    CGContextAddLineToPoint(context, aPoint.x, aPoint.y);
}
[[UIColor redColor] setFill];
[[UIColor blackColor] setStroke];
CGContextDrawPath(context, kCGPathFillStroke);
Run Code Online (Sandbox Code Playgroud)

我想绘制渐变而不是纯红色,但我遇到了麻烦.我已经尝试了问题/答案中列出的代码:iPhone上的UIView和UILabels上的渐变

这是:

CAGradientLayer *gradient = [CAGradientLayer layer];
[gradient setFrame:rect];
[gradient setColors:[NSArray arrayWithObjects:(id)[[UIColor blueColor] CGColor],
                (id)[[UIColor whiteColor] CGColor], nil]];
[[self layer] setMasksToBounds:YES];

[[self layer] insertSublayer:gradient atIndex:0];
Run Code Online (Sandbox Code Playgroud)

然而,这描绘了整个视图,它与渐变一起,掩盖了我的原始路径.

iphone core-graphics quartz-graphics drawrect

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

如何从2D java数组中获取列?

我知道2d数组是数组的数组.要获得一行,你可以做:

rowArray = my2Darray[row]
Run Code Online (Sandbox Code Playgroud)

由于每行可以是不同的大小,我假设它不是为了从2D数组中获取列而构建的.这让我相信你必须做的事情如下:

for(int row = 0; row < numRows; row++)
{
    colArray[row] = m2Darray[row][columnOfInterest];
}
Run Code Online (Sandbox Code Playgroud)

它是否正确?这是唯一的方法吗?

java arrays multidimensional-array

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

在grep中匹配一行与文字星号"*"匹配

试着

$ echo "$STRING" | egrep "(\*)"
Run Code Online (Sandbox Code Playgroud)

并且

$ echo "$STRING" | egrep '(\*)'
Run Code Online (Sandbox Code Playgroud)

和无数其他变化.我只想匹配包含行中任意位置的文字星号的行.

regex bash grep

22
推荐指数
4
解决办法
3万
查看次数

克隆一个git repo,它已经有一个脏工作目录...... Whaaaaa?

所以,我对发生了什么感到困惑.我从来没有攻击过linux内核,所以也许这很常见.如果是这样的话,抱歉新问题.

$ git clone https://github.com/torvalds/linux.git
Run Code Online (Sandbox Code Playgroud)

然后,

$ git status
Run Code Online (Sandbox Code Playgroud)

.

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   include/linux/netfilter/xt_CONNMARK.h
#   modified:   include/linux/netfilter/xt_DSCP.h
#   modified:   include/linux/netfilter/xt_MARK.h
#   modified:   include/linux/netfilter/xt_RATEEST.h
#   modified:   include/linux/netfilter/xt_TCPMSS.h
#   modified:   include/linux/netfilter_ipv4/ipt_ECN.h
#   modified:   include/linux/netfilter_ipv4/ipt_TTL.h
#   modified:   include/linux/netfilter_ipv6/ip6t_HL.h
#   modified:   net/ipv4/netfilter/ipt_ECN.c
#   modified:   net/netfilter/xt_DSCP.c
#   modified:   net/netfilter/xt_HL.c
#   modified:   net/netfilter/xt_RATEEST.c …
Run Code Online (Sandbox Code Playgroud)

git

21
推荐指数
4
解决办法
6427
查看次数

如何在NSArray中找到某种对象?

我的第一直觉是

FooType *myFoo = nil;
for (id obj in myArray) {
    if ( [obj isKindOfClass:[FooType class]] ) myFoo = obj;
}
Run Code Online (Sandbox Code Playgroud)

有了Objective-C和NSArray的所有好东西,就必须有更好的方法,对吧?

objective-c nsarray

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

C中的敏感行缓冲区大小?

我正在使用popen来读取shell命令的输出.我将使用fgets逐行读取.我的问题是如何为我的char*缓冲区选择最佳缓冲区大小?我记得一位教授告诉我们要包含<limits.h>和使用LINE_MAX这些东西.它在我的Mac上工作正常,但LINE_MAX在Linux上却没有.

这个邮件列表存档提出了同样的问题,但没有回答我的问题 http://bytes.com/topic/c/answers/843278-not-able-locate-line_max-limits-h

c file-io buffer fgets

4
推荐指数
2
解决办法
2935
查看次数

C如何为数组字符串获取数组偏移量?

我正在为类做一些事情,我想根据某些条件使用不同的格式字符串.我这样定义它:

const char *fmts[] = {"this one is a little long", "this one is short"};
Run Code Online (Sandbox Code Playgroud)

以后,我可以用

printf(fmts[0]);
Run Code Online (Sandbox Code Playgroud)

要么

printf(fmts[1]);
Run Code Online (Sandbox Code Playgroud)

它的工作原理.

编译器是否为我们做了些什么?我的猜测是它需要最长的字符串并存储所有这些字符串.但我想知道一个知道的人.谢谢

c arrays string

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

如何让gcc中的链接器识别OpenCL库函数?

我正熟悉OpenCL.不过,我确定这个问题不是OpenCL特有的.

我的主文件的顶部看起来像:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <OpenCL/opencl.h>

// some code

cl_device_id device_id; //declaring a device id gives no errors

int err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);
//the above API call does give an error.
Run Code Online (Sandbox Code Playgroud)

我在Snow Leopard上这样做.我可以使用XCode构建和运行Apple的示例.我也可以通过运行make来编译和运行NVIDIA的示例代码.

如何在不使用XCODE的情况下正确编译代码?

xcode gcc makefile opencl

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

如何用字符串唯一标识nsmangedobject?

我正在使用核心数据和区域监控.区分受监视区域的唯一方法是使用NSString作为标识符.我喜欢使用NSManagedObjectID,但我无法让它工作.

我尝试过的:

NSURL *objURL = [managedObjectID URIRepresentation];
NSError *err;
NSString *identifier = [NSString stringWithContentsOfURL:myURL
                                                encoding:NSASCIIStringEncoding
                                                   error:&err];
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

The operation couldn’t be completed. (Cocoa error 256.)
Run Code Online (Sandbox Code Playgroud)

有更好的方法吗?或者我做错了什么?

iphone core-data nsurl nsstring nsmanagedobject

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

如何确保只有支持Region Monitoring的设备可以在商店中查看我的应用程序?

Apple的位置感知编程指南建议包括location-services和可能的gpsfor UIRequiredDeviceCapabilities.

我的应用程序需要区域监控API.如何确保只有功能强大的设备才能在商店中看到我的应用?

iphone location app-store ios

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