我正以这种方式画一个圆圈:
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)
我想知道怎样才能让圆圈内部变空,这样我才能看到它背后的东西.
我以这种方式将许多不同的图像保存到文档目录:
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) 我试过这个:
NSInteger numberFinal = 100000000000000000 + ((float)arc4random() / UINT32_MAX) * (999999999999999999 - 100000000000000000);
Run Code Online (Sandbox Code Playgroud)
但它返回零...我不想指定范围,但只想要任何18位数的数字......
我正在使用此代码阻止用户超过我设置的限制:
在视图中加载:
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年.有任何想法吗?
我有很多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)
有任何想法吗??
我正在以这种方式创建一个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大小,结果都一样,弹出窗口占据了我视图的所有高度和宽度的一半.为什么是这样?
我UIButton的标题长度超过按钮本身的宽度.在UITextField我看到字符串的第一部分(我想要显示的那个)然后是三个点时,UIButton我看到第一部分,然后是中心三个点然后是第三个部分.有没有办法解决这个问题而不实际切割字符串?
ios ×7
objective-c ×4
xcode ×3
cgcontext ×1
nsstring ×1
random ×1
swift ×1
uibutton ×1
uitextfield ×1