gpt4 book ai didi

ios - 有条件地更改多段线颜色

转载 作者:行者123 更新时间:2023-11-29 11:56:47 25 4
gpt4 key购买 nike

- (void)loadView {

// Create a GMSCameraPosition that tells the map to display the
// coordinate -33.86,151.20 at zoom level 6.
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:37.551927
longitude:-77.456292
zoom:18];
GMSMapView *mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(37.551709, -77.456510);
GMSMarker *marker = [GMSMarker markerWithPosition:position];
marker.title = @"Hi";
marker.map = mapView;
mapView.settings.myLocationButton = YES;
mapView.myLocationEnabled = YES;
self.view = mapView;

GMSMutablePath *path = [GMSMutablePath path];
[path addCoordinate:CLLocationCoordinate2DMake(37.552243, -77.457415)];
[path addCoordinate:CLLocationCoordinate2DMake(37.551054, -77.455443)];

GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
int x = 0;
if ((x = 1)){
polyline.spans = @[[GMSStyleSpan spanWithColor:[UIColor redColor]]];
}
else polyline.spans = @[[GMSStyleSpan spanWithColor:[UIColor greenColor]]];
polyline.strokeWidth = 10.f;
polyline.map = mapView;}

我正在尝试根据条件更改这条多段线的颜色。我是 XCode 的新手,所以我只是尝试了一个 if 语句,但由于某种原因它不起作用。任何想法,将不胜感激!

最佳答案

您混合了赋值运算符和比较运算符。

= -> 分配新值
== -> 检查左右手值是否相等

不幸的是,它仍然是一个有效的“条件”语句,尽管它意味着不同的东西。

if (x = 1) -> 如果赋值成功(即 x 中的值被认为是 true)
if (x == 1) -> 如果 x 等于 1

关于ios - 有条件地更改多段线颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38797786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com