When I change the label constraint in the sectionheader, as long as I add constant, it will appear: "unable to synchronously satisfy constraints."
I want to set constraint for a label where in the tableview sectionHeader. But when I add constant, I see "Unable to simultaneously satisfy constraints".
so......what should I do.....
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UITableViewHeaderFooterView()
headerView.backgroundView = {
let view = UIView()
view.backgroundColor = .red
return view
}()
headerView.translatesAutoresizingMaskIntoConstraints = false
let headerLabel = UILabel()
headerView.contentView.addSubview(headerLabel)
headerLabel.translatesAutoresizingMaskIntoConstraints = false
headerLabel.text = "\(data[section]) Hello WorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHello"
headerLabel.numberOfLines = 0
NSLayoutConstraint.activate([
headerLabel.topAnchor.constraint(equalTo: headerView.contentView.topAnchor, constant: 16),
headerLabel.bottomAnchor.constraint(equalTo: headerView.contentView.bottomAnchor),
headerLabel.trailingAnchor.constraint(equalTo: headerView.contentView.trailingAnchor),
headerLabel.leadingAnchor.constraint(equalTo: headerView.contentView.leadingAnchor)
])
return headerView
}
do you know?
how many words do you know
See also questions close to this topic
-
Command failed: xcrun instruments -s
I want to run my react native app on a real ios device with this line :
npx react-native run-ios --udid SOME-UDID
but i got this error :
xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find instruments 2> /dev/null' failed with exit code 17664: (null) (errno=No such file or directory) xcrun: error: unable to find utility "instruments", not a developer tool or in PATH error Command failed: xcrun instruments -s xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find instruments 2> /dev/null' failed with exit code 17664: (null) (errno=No such file or directory) xcrun: error: unable to find utility "instruments", not a developer tool or in PATH
everything is ok on simulator
I'm using XCODE 13
-
IOS Launcher in android studio
I'm trying to change the whole Android OS installed app icons into IOS icons, please help me with the proper code or library for android kotlin
-
Debugging undefined is not an object (evaluating 'Object.keys(routeConfigs)')
I'm using Expo and React Native to create a simple iOS app. I am currently getting this error and have no idea how to fix it. I've tried various other solutions on Stack Overflow to no avail.
My code is:
import 'react-native-gesture-handler'; import React from 'react'; import { createStackNavigator } from 'react-navigation-stack'; import { NavigationContainer } from '@react-navigation/native'; import HomeScreen from './src/screens/HomeScreen'; const Stack = createStackNavigator(); export default function App() { return ( <NavigationContainer> <Stack.Navigator> <Stack.Screen name="Home" component={HomeScreen} /> </Stack.Navigator> </NavigationContainer> ); }
Here is my
HomeScreen.js
import React from 'react'; import { Text, View } from 'react-native'; export default function HomeScreen () { return ( <View> <Text>Welcome Home!</Text> </View> ) }
My packages:
"packages": { "": { "name": "safey", "version": "1.0.0", "dependencies": { "@react-native-community/masked-view": "^0.1.11", "@react-navigation/native": "^6.0.10", "@react-navigation/stack": "^6.0.10", "expo": "~45.0.0", "expo-splash-screen": "~0.15.1", "expo-status-bar": "~1.3.0", "react": "17.0.2", "react-dom": "17.0.2", "react-native": "0.68.1", "react-native-gesture-handler": "^2.4.2", "react-native-reanimated": "^2.8.0", "react-native-safe-area-context": "^4.2.5", "react-native-screens": "^3.13.1", "react-native-web": "0.17.7", "react-navigation": "^4.4.4", "react-navigation-stack": "^2.10.4" },
-
SwiftUI, apply drawGesture only when over Image
I'm try to apply the gesture only when the user is over the Image display not when tapped outside the image.
Any suggestion how I can do? this following code draw also when user tap outside the image.
struct ContentView: View { @StateObject var am = AppManager() @State var switchToTakePicture = false @State var paths: [PathContainer] = [] @State var currentDraggingId = UUID() @State var spikoPic = #imageLiteral(resourceName: "spiko-16.jpeg") @State var centerOFimage = CGSize(width: 0, height: 0) var body: some View { GeometryReader { proxy in ZStack { Image(uiImage: spikoPic) .resizable() .scaledToFit() .position(x: proxy.size.width/2, y: proxy.size.height/2) .background(GeometryReader { Color.clear.preference(key: ViewRectKey.self, value: [$0.frame(in: .global)]) }) .gesture(drawGesture) // not correct ForEach(paths) { container in // draw and set the foreground color of the paths to red container.path .stroke(Color.red, lineWidth: 4) } } .onPreferenceChange(ViewRectKey.self) { rects in print(rects.first ?? .zero) } } } var drawGesture: some Gesture { DragGesture(minimumDistance: 0) .onChanged { value in // The point that the gesture started from let start = value.startLocation // The point that the gesture ended to let end = value.location // the properties of the rectangle to be drawn let rectangle: CGRect = .init(origin: end, size: .init(width: start.x - end.x, height: start.y - end.y)) // create a path for the rectangle let path: Path = .init { path in path.addRect(rectangle) } print("rettangolo = \(rectangle) orig \(rectangle.origin) - height \(rectangle.height) width = \(rectangle.width)") // remove the previous rectangle that was drawen in current // process of drawing paths.removeAll { $0.id == currentDraggingId } // append the new rectangle paths.append(.init(id: currentDraggingId, path: path)) } .onEnded { _ in // renew the dragging id so the app know that the next // drag gesture is drawing a completely new rectangle, // and is not continuing the drawing of the last rectangle currentDraggingId = .init() } } }
i want no box outside
-
How to navigate between NavigationLink while leave a part of main window stay the same in SwiftUI
I would like to navigate between different
NavigationLink
s inNavigationView
while some part of the main window stay the same. For example, I want to make a music app and I want to let the play controller always on top, while I can display different navigation contents (songs page, artists page...) using the rest of the window.Like what's showed in the picture below, I want to keep the red part always there while the blue part changes.
My code would be like below, but it won't work correctly. The
AlwaysStayView()
disappears when I click anyNavigationLink
on sidebar. So, how can I correct it or is there any solution (prefer in SwiftUI, but framework like UIKit would also be OK). I would appreciate it.NavigationView { List { NavigationLink { DiscoverView() } label: { Label("Discover", systemImage: "magnifyingglass") } NavigationLink { SongsView() } label: { Label("Songs", systemImage: "music.note") } NavigationLink { ArtistsView() } label: { Label("Artists", systemImage: "music.mic") } } } .listStyle(SidebarListStyle()) VStack { AlwaysStayView() SongsView() } }
-
NumberFormatter and unsigned with UInt64.max
I'm trying to create a string representing
UInt64.max
usingNumberFormatter
. Here's the code:let formatter = NumberFormatter() formatter.usesGroupingSeparator = true formatter.numberStyle = .decimal formatter.positiveFormat = "# ##0.#########" formatter.maximumSignificantDigits = 20 formatter.usesSignificantDigits = false formatter.maximumFractionDigits = 20 formatter.minimumFractionDigits = 0 formatter.alwaysShowsDecimalSeparator = false // formatter.roundingMode = .halfUp let text1 = formatter.string(for: NSNumber(value: Int64.max)) let text2 = formatter.string(for: NSNumber(value: UInt64.max)) print(text1) print(text2)
which prints:
Optional("9,223,372,036,854,780,000")
Optional("-1")but should print
Optional("9223372036854775807")
Optional("18,446,744,073,709,551,615")It looks like
NSNumber
is roundingInt64
and isn't taking theUIn64
. The obj-c version ofNSNumberFormatter
works fine.Am I missing something or is there a problem with
NumberFormatter
? -
How to set a ConstrainedBox for a bottomNavigationBar | Flutter
I was trying to setup a
bottomNavigationBar
with:ConstrainedBox( constraints: const BoxConstraints(maxWidth: 500), child: // child (Two buttons, occupying each ~40% of the total width )
But when I do this, the
bottomNavigationBar
takes the full width of the display (an iPad Pro 11''), and I only want thisbottomNavigationBar
to take so much space (less than 500)Anyone knows what's the problem? I have this
ConstrainedBox
for the body and there's no issueThanks! :)
-
Android compose need to place a constraintlayout on top of the UI
I am taking my first steps at jetpack Compose and currently i am developing a recyclerview-like list by using Card (and other compoenent layouts). For my application i have an xml include layout which is of type Constriantlayout and i need this one to be at the top of the UI.
Here is my code currently:
package com.example.cvdriskestimator.Fragments class leaderBoardActivity : ComponentActivity() { private var participantNames = ArrayList<String>() private var participantAvatars = ArrayList<Drawable>() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { Scaffold() { ConstraintCompose() participantList() } } } @Composable fun ConstraintCompose() { ConstraintLayout(modifier = Modifier .fillMaxHeight() .fillMaxWidth()) { val (medAppLayoutRefId) = createRefs() Box(modifier = Modifier.constrainAs(medAppLayoutRefId) { top.linkTo(parent.top, 0.dp) }) { AndroidView( { context: Context -> val view = LayoutInflater.from(context) .inflate(R.layout.cvd_title_form, null, false) // do whatever you want... view // return the view } ) } } } @Preview @Composable fun participantList() { Row(modifier = Modifier .clip(RoundedCornerShape(10.dp)) .background(MaterialTheme.colors.surface)) { val scrollState = rememberLazyListState() LazyColumn(state = scrollState, modifier = Modifier.border( 5.dp, Color.DarkGray , shape = RoundedCornerShape(60.dp))){ items(participantList) { participant -> run { participantCard( participantList.indexOf(participant) , userName = participant.participantName, participantImage = participant.participantDrawable ) } } } } } @Composable fun participantCard( userID : Int , userName : String , participantImage : Int) { Card(elevation = 5.dp , modifier = Modifier .fillMaxWidth() .wrapContentHeight() .padding(5.dp) ) { Row(modifier = Modifier .padding(5.dp) .fillMaxWidth() .wrapContentHeight() , horizontalArrangement = Arrangement.Center , verticalAlignment = Alignment.CenterVertically , ) { Text( color = Color.Black , fontSize = 20.sp , fontFamily = FontFamily.Default , textAlign = TextAlign.Center , text = userID.toString() + ". " + userName ) Image(painterResource(id = participantImage), contentDescription = "participant image" , modifier = Modifier .size(20.dp, 20.dp) .clip( CircleShape ) ) Box(modifier = Modifier .fillMaxWidth() .wrapContentHeight() .padding(5.dp, 0.dp, 0.dp, 5.dp)) { Text(color = Color.Black, fontSize = 20.sp, modifier = Modifier .border(2.dp, Color.Gray) .padding(10.dp) , text = "Score : " + setParticipantScore(userID ).toString()) } Image(painterResource(id = R.drawable.ic_trophy) , contentDescription = "Participant Trophy" , modifier = Modifier.size(20.dp , 20.dp)) } } } private fun setParticipantScore(id : Int) : Int { return ((10000) - (id * 500)) } val participantList = listOf<participant>( participant("Lampros " , R.drawable.avatar) , participant("Chris" , R.drawable.avatar_b) , participant("Dimitris" , R.drawable.beard) , participant("Kostas" , R.drawable.boy) , participant("Panagiotis" , R.drawable.gamer) , participant("Nikoleta" , R.drawable.woman) , participant("Dimitra" , R.drawable.womanb) , participant("Kyriakos" , R.drawable.man_a) , participant("Giannis" , R.drawable.man_b) ) data class participant( var participantName : String , var participantDrawable : Int ) }
As an output though i am getting only the card list, so i am guessing there is some problem with how i am defining the constraintlayout and using it programmatically? When i preview the function of ConstraintCompose seperately i can see the layout appearing in the UI Layout.
Any help is appreciated.
Lampros
-
maya python kill constraints properly
Hello everybody
I wrote a script that allows me to smart bake and kill constraints to a selected object in the scene. It works as intended, the only problem is that it doesnt remove the blendParent node in the channel box.this is the script:
#Bake and kill constraint def FD_simple_SmartBake(): #loc list userSel = [] len(userSel) # get the user selection sel = mc.ls(sl=1) userSel.append(sel) if len(sel) != 0: #for loc in LocList: # mc.select (loc, add=1) start = mc.playbackOptions(q=True, min=True) end = mc.playbackOptions(q=True, max=True) mc.bakeResults(sm=1, sr=1, t=(start, end)) else: mc.warning('Please make a selection') for obj in sel: mc.delete(cn=1) FD_simple_SmartBake()
if I just run the code to kill the constraint
mc.delete(cn=1)
without all the function, it works fine and remove the blendParent label from the channel box .... Something stupid I think but i dont understand whyAny help would be greatly appreciated Thanks Flys
-
how to add a searchbar in a tableview with a parsed JSON file
I have successfully parsed a JSON file with the following data model into my project and my tableview.
import Foundation struct ActionResult: Codable { let data: [Datum] } struct Datum: Codable { let goalTitle, goalDescription, goalImage: String let action: [Action] } struct Action: Codable { let actionID: Int let actionTit: String }
Now I am trying to create a searchbar to search on the "actionTitle". My tableview has section headers and rows.
Relevant code:
var filteredData: [Action]? let searchController = UISearchController() override func viewDidLoad() { super.viewDidLoad() title = "Search" searchController.searchBar.delegate = self filteredData = ???? navigationItem.searchController = searchController parseJSON() func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { filteredData = [] if searchText == ""{ filteredData = ???? } else { for actions in ???? { if actions.lowercased().contains(searchText.lowercased()) { filteredData.append(actions) } self.tableView.reloadData() }
I do not know what code to use where I have ????.
Thanks.
-
Adding scope buttons to search bar doesn't work
I used the TableSearch sample from Apple to implement my own search in the app I'm working on.
It seems that the sample is bugged. The scope buttons will display the result controller only if something is entered in the search field. But, looking at the code, that doesn't seem the case because they specifically check for search items being empty or not:
if !searchItemsPredicate.isEmpty { /** We have a scope type and other fields to search on - so match up the fields of the Product object AND its product type. */ let compPredicate1 = NSCompoundPredicate(orPredicateWithSubpredicates: searchItemsPredicate) let compPredicate2 = NSPredicate(format: "(SELF.type == %ld)", selectedScopeButtonIndex) finalCompoundPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [compPredicate1, compPredicate2]) } else { // Match up by product scope type only. finalCompoundPredicate = NSCompoundPredicate(format: "(SELF.type == %ld)", selectedScopeButtonIndex) }
So, if the search items predicate is empty (meaning nothing has been entered in the search field), the code is supposed to filter according to the product type. But that doesn't work when you run the app. However, if you just put a space into the search field, then the code filters the products correctly and displays the result controller. I've been trying to fix this but I haven't been able to find the relation between the content of the search field and the scope buttons.
Anybody has any idea?
-
Load only currently logged-in user data in cells. (Firebase)
I have an app with a SignUp/LogIn authentication created with Firebase. When the user is connected, he can add a cell and fill in two text fields. Then the cell data like the date, the two fields filled by the user and the email of the user who created the cell are saved with Firestore. I want that when a user logs in, only the cells that this user has created are displayed. How I can do it?
Here is my FStore struct :
struct FStore { static let collectionName = "cells" static let firstText = "firstText" static let secondText = "secondText" static let senders = "sender" static let dateField = "date" }
Here I save the cell informations :
let firstBody = alert.textFields![0] as UITextField let secondBody = alert.textFields![1] as UITextField if firstBody.text != "" && secondBody.text != "" { if let cellSender = Auth.auth().currentUser?.email { self.db.collection(Constants.FStore.collectionName).addDocument(data: [Constants.FStore.senders: cellSender, Constants.FStore.firstText: firstBody.text!, Constants.FStore.secondText: secondBody.text!, Constants.FStore.dateField: Date().timeIntervalSince1970]) { error in if let e = error { print("Issue saving data to Firestore \(e)") } else { print("succesfully saved") } } }
CELLS struct :
struct CELLS { let sender: String let firstText: String let secondText: String }
Load Cell function (CellArray = [CELLS]) :
func loadCells() { CellArray = [] db.collection(Constants.FStore.collectionName).order(by: Constants.FStore.dateField).addSnapshotListener { querySnapshot, error in self.CellArray = [] if let e = error { print("issue retrieving data \(e)") }else { if let snapshotDocuments = querySnapshot?.documents { for doc in snapshotDocuments { let data = doc.data() if let sender = data[Constants.FStore.senders] as? String, let cellFirst = data[Constants.FStore.firstText] as? String, let cellSecond = data[Constants.FStore.secondText] as? String { let newCell = CELLS(sender: sender, firstText: cellFirst, secondText: cellSecond) self.CellArray.append(newCell) DispatchQueue.main.async { self.tableView.reloadData() } } } } } } }
And now I want to return only the user cells here :
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { // Return only the currently logged-in user cells return CellArray.count }
Thanks for your help.
-
ios15 UITableView Section Label font size and color was change
After upgrading ios14 to ios15, the font size and color of the label in the section of uitableview have changed.
Is there any global solution.
My current method is like this, but I can only solve one tableview
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section { UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view; header.textLabel.textColor = [UIColor colorWithRed:0.137f green:0.137f blue:0.137f alpha:1.0]; header.textLabel.font = [UIFont boldSystemFontOfSize:17]; NSLog(@"title size is %f",header.textLabel.font.pointSize); }
LOG:
IOS14: title size is 17.000000
IOS15: title size is 15.000000 -
Lable and button in the header section view UITableView
I am trying to add a section title Label and a button in the header section view. but it looks empty. when I run the application the header is empty. the 2nd section code work fine
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { if (section == 0){ let label = UILabel.init(frame: CGRect.init(x: 17, y: 139, width: tableView.frame.size.width, height: 45)) label.textColor = UIColor.black label.font = UIFont.systemFont(ofSize: 13.0) label.textAlignment = .left label.text = " My Balances" label.backgroundColor = UIColor(red: 0.95, green: 0.95, blue: 0.95, alpha: 1.00) let frame = tableView.frame let height:CGFloat = 66 let button = UIButton(frame: CGRect(x: 306, y: 139, width: 15, height: 15)) // create button button.tag = section // the button is image - set image button.setImage(UIImage(named: "remove_button"), for: .normal) let headerView = UIView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: height)) // create custom view headerView.addSubview(button) // add the button to the view headerView.addSubview(label) return headerView //return label //return label } else { let label = UILabel.init(frame: CGRect.init(x: 0, y: 241, width: tableView.frame.size.width, height: 45)) label.textColor = UIColor.black label.font = UIFont.systemFont(ofSize: 13.0) label.textAlignment = .left label.text = " My Customers" label.backgroundColor = UIColor(red: 0.95, green: 0.95, blue: 0.95, alpha: 1.00) return label } }