小编use*_*474的帖子

在iOS中使用核心图形上下文绘制一个圆圈 - Objective-C或Swift

我正以这种方式画一个圆圈:

CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(contextRef, 2.0);
//CGContextSetRGBFillColor(contextRef, 0, 0, 1.0, 1.0);
//CGContextSetRGBStrokeColor(contextRef, 0, 0, 1.0, 1.0);
 CGContextSetStrokeColorWithColor(contextRef, [color CGColor]);
CGRect circlePoint = (CGRectMake(coordsFinal.x, coordsFinal.y, 50.0, 50.0));

CGContextFillEllipseInRect(contextRef, circlePoint);
Run Code Online (Sandbox Code Playgroud)

我想知道怎样才能让圆圈内部变空,这样我才能看到它背后的东西.

objective-c cgcontext ios swift

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

文件目录订单文件?IOS

我以这种方式将许多不同的图像保存到文档目录:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

int num = arc4random() % 100000000000000;

NSString* path = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat:@"%dtest.png", num]];
NSData* data = UIImagePNGRepresentation(image);
[data writeToFile:path atomically:YES];
Run Code Online (Sandbox Code Playgroud)

然后我用这种方式读取文件:

NSString *stringPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES)objectAtIndex:0];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//NSString* FinalPath = [documentsDirectory stringByAppendingPathComponent: @"Images/"];

NSArray *filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory  error:&error];

for(int i=0;i<[filePathsArray count];i++)
{
    NSString *strFilePath = [filePathsArray objectAtIndex:i];
    if ([[strFilePath pathExtension] isEqualToString:@"jpg"] || [[strFilePath pathExtension] …
Run Code Online (Sandbox Code Playgroud)

objective-c nsfilemanager ios

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

生成任意18位数的随机NSInteger

我试过这个:

NSInteger numberFinal = 100000000000000000 + ((float)arc4random() / UINT32_MAX) * (999999999999999999 - 100000000000000000);
Run Code Online (Sandbox Code Playgroud)

但它返回零...我不想指定范围,但只想要任何18位数的数字......

random objective-c ios

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

UIDatePicker设置最大日期

我正在使用此代码阻止用户超过我设置的限制:

在视图中加载:

NSDate *Date=[NSDate date];
[DatePickerForDate setMinimumDate:Date];
[DatePickerForDate setMaximumDate:[Date dateByAddingTimeInterval: 63072000]]; //time interval in seconds
Run Code Online (Sandbox Code Playgroud)

而这种方法:

- (IBAction)datePickerChanged:(id)sender{
if ( [DatePickerForDate.date timeIntervalSinceNow ] < 0 ){
    NSDate *Date=[NSDate date];
    DatePickerForDate.date = Date;
}

if ( [DatePickerForDate.date timeIntervalSinceNow ] > 63072000){
    NSDate *Date=[NSDate date];
    DatePickerForDate.date = Date;
}
}
Run Code Online (Sandbox Code Playgroud)

第一部分工作(一个<0),并返回当前日期,但一个> 63072000,有时工作,有时不工作.顺便说一句63072000约为2年.有任何想法吗?

xcode ios

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

从NSStrings中提取数字

我有很多NSString,看起来像这样:

@"this is the content. The content of this string may vary, as well as the length, and my include any characters, with numbers Y = 295.000000 X = 207.500000"
Run Code Online (Sandbox Code Playgroud)

除了可能改变的X和Y数之外,Y = 295.000000 X = 207.500000的部分总是相同的.

我需要以某种方式获取这些数字并执行以下操作:

coordsFinal.x = 295.000000;
coordsFinal.y = 207.500000;
Run Code Online (Sandbox Code Playgroud)

其格式为:

coordsFinal.x = [NSString stringWithFormat: @"%@", trimmed string];
Run Code Online (Sandbox Code Playgroud)

有任何想法吗??

xcode ios

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

UIPopoverController设置框架大小

我正在以这种方式创建一个popover:

popoverController = [[UIPopoverController alloc]initWithContentViewController:browser];
[popoverController presentPopoverFromRect:CGRectMake(44, 400, 600, 800) inView:self.view permittedArrowDirections:0 animated:YES];
Run Code Online (Sandbox Code Playgroud)

由于一些奇怪的原因,无论我放置什么CGRectMake大小,结果都一样,弹出窗口占据了我视图的所有高度和宽度的一半.为什么是这样?

xcode ios

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

UIButton中的长名称缩短了

UIButton的标题长度超过按钮本身的宽度.在UITextField我看到字符串的第一部分(我想要显示的那个)然后是三个点时,UIButton我看到第一部分,然后是中心三个点然后是第三个部分.有没有办法解决这个问题而不实际切割字符串?

objective-c uibutton nsstring uitextfield ios

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