如何将我的 obj C 代码转换为 swift 代码
How can I convert my obj C code to swift code
我开始使用 Swift 编写 iOS,对 objective C 一无所知,谁能帮我把用 objective C 编写的代码转换成 Swift 4.
UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 50)];
iconView.image = [UIImage imageNamed:@"my-icon-image"];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 35, 50)];
label.text = @"test";
[iconView addSubview:label];
UIGraphicsBeginImageContextWithOptions(label.bounds.size, NO, [[UIScreen mainScreen] scale]);
[iconView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *icon = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(lat, lng);
marker.title = @"my title";
marker.icon = icon;
marker.map = mapView;
另外,如果有人知道免费的翻译器,请分享。
给你
// Converted to Swift 5.2 by Swiftify v5.2.18740 - https://swiftify.com/
let iconView = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 50))
iconView.image = UIImage(named: "my-icon-image")
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 35, height: 50))
label.text = "test"
iconView.addSubview(label)
UIGraphicsBeginImageContextWithOptions(label.bounds.size, _: false, _: UIScreen.main.scale)
if let context = UIGraphicsGetCurrentContext() {
iconView.layer.render(in: context)
}
let icon = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(lat, lng)
marker.title = "my title"
marker.icon = icon
您可以使用 https://swiftify.com/#/converter/code/ 来编写一小段代码
我开始使用 Swift 编写 iOS,对 objective C 一无所知,谁能帮我把用 objective C 编写的代码转换成 Swift 4.
UIImageView *iconView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 50)];
iconView.image = [UIImage imageNamed:@"my-icon-image"];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 35, 50)];
label.text = @"test";
[iconView addSubview:label];
UIGraphicsBeginImageContextWithOptions(label.bounds.size, NO, [[UIScreen mainScreen] scale]);
[iconView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *icon = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(lat, lng);
marker.title = @"my title";
marker.icon = icon;
marker.map = mapView;
另外,如果有人知道免费的翻译器,请分享。
给你
// Converted to Swift 5.2 by Swiftify v5.2.18740 - https://swiftify.com/
let iconView = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 50))
iconView.image = UIImage(named: "my-icon-image")
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 35, height: 50))
label.text = "test"
iconView.addSubview(label)
UIGraphicsBeginImageContextWithOptions(label.bounds.size, _: false, _: UIScreen.main.scale)
if let context = UIGraphicsGetCurrentContext() {
iconView.layer.render(in: context)
}
let icon = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(lat, lng)
marker.title = "my title"
marker.icon = icon
您可以使用 https://swiftify.com/#/converter/code/ 来编写一小段代码