如何使NavigationBarTitle和navigationBarItem的重叠区域可点击-SwiftUI

时间:2019-12-10 12:43:49

标签: ios swift iphone xcode swiftui

当前只有红色区域的中间部分是可轻敲的,我知道下面的区域与navigationBarTitle重叠,但是我仍然想知道是否也可以使下面的区域可轻敲。

enter image description here

var requestUrl = "urlofapi";
            var token = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{siteId}:{apiKey}"));
            HttpWebRequest http = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
            http.Headers.Add("Authorization", $"Basic {token}");
            http.ContentType = "application/json; charset=utf-8";
            http.Method = "POST";
            JsonSerializerSettings _jsonSerializerSettings = new JsonSerializerSettings()
            {
                MissingMemberHandling = MissingMemberHandling.Ignore,
                NullValueHandling = NullValueHandling.Ignore,
                DefaultValueHandling = DefaultValueHandling.Include,
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };

            using (var streamWriter = new StreamWriter(http.GetRequestStream()))
            {
                string json = JsonConvert.SerializeObject(data, _jsonSerializerSettings);
                streamWriter.Write(json);
                streamWriter.Flush();
            }

            HttpWebResponse response = (HttpWebResponse)http.GetResponse(); // Got default response from the application not the actual data response.
            using (StreamReader sr = new StreamReader(response.GetResponseStream()))
            {
                string responseJson = sr.ReadToEnd();
                // more stuff
            }

enter image description here

1 个答案:

答案 0 :(得分:0)

您的代码有两个小改动

.navigationBarItems(
            leading: EditButton(),
            trailing:
            Button(
                action: { self.modalIsPresented = true }
            ) {
                Image(systemName: "plus")
                .padding()
                .background(Color.red)
            }
        )