我在iOS应用程序中使用谷歌地图,并实现了一个自定义信息窗口,用于显示标记的标题.
现在,我在该自定义信息窗口上添加了一个按钮,但我的问题是没有调用按钮操作方法.
CustomInfoWindow.h
#import <UIKit/UIKit.h>
@interface CustomInfoWindow : UIView
@property (nonatomic,weak) IBOutlet UILabel *addressLabel;
@property(nonatomic) IBOutlet UIButton *button;
@end
Run Code Online (Sandbox Code Playgroud)
在infoWindow.xib,我补充说
UILabel 叫 addressLabelUIButton 叫 buttonViewController.h
#import "CustomInfoWindow.h"
@interface viewController : UIViewController<GMSMapViewDelegate>
{
GMSMapView *mapView;
}
@end
Run Code Online (Sandbox Code Playgroud)
ViewController.m
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
NSLog(@"Mrker Tapped");
CustomInfoWindow *infoWindow = [[[NSBundle mainBundle]loadNibNamed:@"infoWindow"
owner:self
options:nil] objectAtIndex:0];
infoWindow.addressLabel.text = marker.title;
[infoWindow.button addTarget:self action:@selector(ButtonPressed)
forControlEvents:UIControlEventTouchUpInside];
return infoWindow;
}
-(void)ButtonPressed
{
NSLog(@"Button Pressed");
}
Run Code Online (Sandbox Code Playgroud)
基本上...... ButtonPressed方法不会开火.
将所有这些代码包装在一个块中的原因是什么UI: do { }?我在哪里可以获得有关它的明确说明?
UI: do {
backgroundButton.setImage(UIImage.init(named: "search"), for: .normal)
backgroundButton.backgroundColor = Colors.backgroundButtonBackgroundColor
backgroundButton.tintColor = Colors.backgroundButtonTintColor
}
Run Code Online (Sandbox Code Playgroud) 我UIDatePicker在我的视图中有一个设置背景颜色UIDatePicker:
self.datePicker.backgroundColor = [UIColor lightTextColor];
self.datePicker.layer.cornerRadius = 10;
Run Code Online (Sandbox Code Playgroud)
这成功地将背景置于背后UIDatePicker(在iOS7中基本上是透明的)但是未能为我正在寻找的背景制作圆角(我对屏幕上的图像做同样的事情并且它完美地工作).
看起来角半径不会影响背景颜色.
有没有办法通过设置背景颜色(或任何其他解决方案)的角半径来解决此问题.
我想这样做的原因是因为普通UIDatePicker在我构造的视图中看起来很笨拙,并且背景颜色看起来更好.
但是,视图中的所有其他项目都有圆角,我希望UIDatePicker匹配它们.
谢谢.
我目前有以下代码来设置密码文本字段:
self.passwordTextField = [UITextField new];
self.passwordTextField.placeholder = @"Password";
self.passwordTextField.font = [UIFont systemFontOfSize:18.f];
self.passwordTextField.secureTextEntry = YES;
self.passwordTextField.returnKeyType = UIReturnKeyDone;
self.passwordTextField.delegate = self;
self.passwordTextField.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:0.64];
self.passwordTextField.layer.borderColor = [[UIColor lightGrayColor] CGColor];
self.passwordTextField.layer.borderWidth = 1.0f;
CGFloat textFieldHeight = 45.f;
CGFloat textFieldWidth = 300.f;
self.passwordTextField.frame = CGRectMake(DIALOG_VIEW_WIDTH/2.f - textFieldWidth / 2.f, 240.f, textFieldWidth, textFieldHeight);
UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"text-input-icon-password-key.png"]];
icon.frame = CGRectMake(0, 0, 45.f, 45.f);
icon.backgroundColor = [UIColor lightGrayColor];
self.passwordTextField.leftView = icon;
self.passwordTextField.leftViewMode = UITextFieldViewModeAlways;
[self.dialogView addSubview:self.passwordTextField];
Run Code Online (Sandbox Code Playgroud)
这给了我这个: …
当我从谷歌寻找答案时,大多数答案都说你试图在NSArray上使用不受支持的长度.
这里的问题是我甚至没有在我的代码中使用任何NSArray或长度.
我有一个
NSMutableArray *filteredContent;
Run Code Online (Sandbox Code Playgroud)
哪里filteredContent将包含来自plist的字典.
一切都很好,直到写cell.textLabel.text在牢房上tableView.
选中NSLog并且内容确实是一个数组.
这是我尝试编写单元格文本的方法:
cell.textLabel.text=[[self.filteredContent objectAtIndex:indexPath.row] valueForKey:@"recipeName"];
Run Code Online (Sandbox Code Playgroud)
但它给了我错误所以我改为:
NSString *myValue = [self.filteredContent valueForKey:@"recipeName"];
cell.textLabel.text=myValue;
Run Code Online (Sandbox Code Playgroud)
但结果是一样的.我不知道我得到了什么错误.
更多详情:
[results addObject:@[recipe]];
Run Code Online (Sandbox Code Playgroud)
这是我创建主数组的地方,而不是将其传递给PageViewwith seguefilteredContent = results
编辑:
recipe = arrayOfPlist[i]; 其中arrayOfPlist
NSArray *arrayOfPlist = [[NSArray alloc] initWithContentsOfFile:path];
//Output to NSLog(@"FIltered Content : %@", self.filteredContent);
FIltered Content : (
(
{
category = main;
difficultyLevel = "3/5";
numberOfPerson = 5;
recipeDetail = "Bulguru koy su koy beklet pisir ye …Run Code Online (Sandbox Code Playgroud) cocoa-touch objective-c uitableview ios unrecognized-selector
我想使用来自 2 个不同文本字段的输入进行计算,并将输出放入文本中。参见代码:
@State var input1: String = ""
@State var input2: String = ""
var calculation : Double {
let calculationProduct = Double(input1) * Double(input2)
return calculationProduct
}
var body: some View {
VStack{
TextField("", text: $input1)
TextField("", text: $input1)
Text("\(calculation)")
}
Run Code Online (Sandbox Code Playgroud)
问题是代码无法编译,我收到不同的编译错误,例如:“二元运算符 '*' 不能应用于两个 'Double?' 操作数”。
出了什么问题?
众所周知,对象是通过引用计数和其他类似算法来工作的。
但是对于原始数据类型,我们无法做到NULL:
int a = NULL;
Run Code Online (Sandbox Code Playgroud)
垃圾收集器如何在Java中用于原始数据类型?
我想创建一个蒙版路径,其最终输出将是一个带凹面的角.
我已经创建了一个UIBezierPath使用该-bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:方法并指定只需要对一个角进行舍入(在此示例中UIRectCornerBottomLeft),我认为通过反转此路径,我应该得到首先要切割的内容.
为此,我正在尝试,-bezierPathByReversingPath但它似乎没有任何区别(有或没有,因为我得到正常的bezier路径,而不是相反)
这是我到目前为止所尝试的:
UIView *vwTest = [[UIView alloc] init];
[vwTest setFrame:CGRectMake(100.0f, 100.0f, 100.0f, 100.0f)];
[vwTest setBackgroundColor:[UIColor redColor]];
[self.view addSubview:vwTest];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:vwTest.bounds
byRoundingCorners:UIRectCornerBottomLeft
cornerRadii:CGSizeMake(50.0f, 50.0f)];
//get reverse path but doesn't seem to work as I think it should
maskPath = [maskPath bezierPathByReversingPath];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
[maskLayer setFrame:vwTest.bounds];
[maskLayer setPath:maskPath.CGPath];
[vwTest.layer setMask:maskLayer];
[vwTest.layer setMasksToBounds:YES];
[vwTest setNeedsDisplay];
Run Code Online (Sandbox Code Playgroud)
根据下面的图像,我想要实现的是显示红色部分UIView并消除其余区域.

暂时,我在subview上做subit,并将一个子视图的颜色与主视图的背景颜色同步(很糟糕,但至少我得到了所需的输出):
[self.view setBackgroundColor:[UIColor lightGrayColor]]; …Run Code Online (Sandbox Code Playgroud) 我在 Swift 中编写了一个图像选择器(NOT UIImagePickerController),按下“完成”后,我返回所选 PHAssets(图像或视频或两者)的 URL,然后将它们上传到 firebase 存储。
图像的 URL 如下所示: file:///var/mobile/Media/DCIM/101APPLE/IMG_1239.PNG
视频的 URL 如下所示: file:///var/mobile/Media/DCIM/101APPLE/IMG_1227.MOV
然后我显示 PHAsset。播放视频资产没有问题:
let player = AVPlayer(url: url)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = view.frame
playerLayer.videoGravity = .resizeAspectFill
view.layer.addSublayer(playerLayer)
player.play()
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用其 URL 显示图像时,出现“无权读取文件”错误:
do {
let data = try Data(contentsOf: url)
imageView.image = UIImage(data: data)
} catch {
print(error)
}
Run Code Online (Sandbox Code Playgroud)
我确实有权访问用户的照片库,这就是图像选择器工作正常的原因。我只是无法使用它们的 URL 读取图像文件。
我在想,也许我应该将图像资产复制到临时文件并从那里读取它,但是为什么视频资产可读但不是图像资产没有任何意义。
- - - - - - - 更新 - - - - - - -
这就是我获取 PHAsset 网址的方式 …
所以我是Obj-C的新手(具有C和C++经验),我一直在努力.
很简单,我想保存并加载用户进度时的分数和级别.
我有3个功能getFilePath,loadData和savaData.
我getFilePath和loadData似乎工作正常,但我不能获得saveData工作.
这是我的代码:
-(void)saveData
{
NSNumber *updatedScore = [NSNumber numberWithInt:score];
NSNumber *updatedLevel = [NSNumber numberWithInt:level];
NSLog(@"The level im saving is %@",updatedLevel);
NSLog(@"The score im saving is %@",updatedScore);
NSMutableArray *value = [[NSMutableArray alloc]initWithObjects:updatedLevel,updatedScore, nil];
[value writeToFile:[self getFilePath] atomically:YES];
}
-(NSString *)getFilePath
{
NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
NSLog(@"the path is %@",pathArray);
return [[pathArray objectAtIndex:0]stringByAppendingPathComponent:@"saved.plist"];
}
Run Code Online (Sandbox Code Playgroud)
我的NSLog消息返回正确的值,用户进展级别,但我无法保存它们.
ios ×7
objective-c ×6
cocoa-touch ×3
swift ×3
avasset ×1
calayer ×1
cashapelayer ×1
cornerradius ×1
google-maps ×1
ios7 ×1
java ×1
nsnumber ×1
phasset ×1
plist ×1
swiftui ×1
uibezierpath ×1
uidatepicker ×1
uitableview ×1
uitextfield ×1
uiview ×1